Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Codeigniter 根据性能,哪种代码更好?_Codeigniter - Fatal编程技术网

Codeigniter 根据性能,哪种代码更好?

Codeigniter 根据性能,哪种代码更好?,codeigniter,Codeigniter,我有一个动态表单,其中数据被添加到数据库中。 我不知道哪种方法更好地从循环外的会话获取一些数据 或者直接从循环中的会话获取数据。 这是我的密码 1-从会话中获取数据并将其放入两个变量中,然后在循环中调用这些变量 $user_name = $this->input->post('user_name'); $organization_name = $this->input->post('organization_name'

我有一个动态表单,其中数据被添加到数据库中。 我不知道哪种方法更好地从循环外的会话获取一些数据 或者直接从循环中的会话获取数据。 这是我的密码 1-从会话中获取数据并将其放入两个变量中,然后在循环中调用这些变量

$user_name                  = $this->input->post('user_name');
 $organization_name          = $this->input->post('organization_name');
 $location                   = $this->input->post('location');
 $duration_time              = $this->input->post('duration_time');
 $yearly_expences            = $this->input->post('yearly_expences');
 $expences_source            = $this->input->post('expences_source');
 $remark                     = $this->input->post('remark');

 //-----
 $u_rec_id = $this->session->userdata('rec_id');
 $serial   = $this->session->userdata('serial');
 //-----
 $all_array = array();

 if( $user_name ) {
    if( is_array( $user_name ) ) {

        for( $j = 0 ; $j < count( $user_name ) ; $j++ ) {
           $this ->ci_form = array(
              'user_name'         => $user_name[$j],
              'organization_name' => $organization_name[$j],
              'location'          => $location[$j],
              'duration_time'     => $duration_time[$j],
              'yearly_expences'   => $yearly_expences[$j],
              'expences_source'   => $expences_source[$j],
              'remark'            => $remark[$j],
              'userid'            => $this->m_auth->get_user_id(),
              'u_rec_id'          => $u_rec_id,
              'serial'            => $serial,
              'regdate'           => date('Y-m-d H:m:s')

          );
          array_push( $all_array, $this->ci_form );
      }
   }
$user\u name=$this->input->post('user\u name');
$organization\u name=$this->input->post('organization\u name');
$location=$this->input->post('location');
$duration\u time=$this->input->post('duration\u time');
$year_expenses=$this->input->post('year_expenses');
$expenses\u source=$this->input->post('expenses\u source');
$remark=$this->input->post('remark');
//-----
$u_rec_id=$this->session->userdata('rec_id');
$serial=$this->session->userdata('serial');
//-----
$all_array=array();
如果($user\u name){
if(is_数组($user_name)){
对于($j=0;$jci_form=array(
“用户名”=>$user\u name[$j],
“组织机构名称”=>$organization\u name[$j],
“位置”=>$location[$j],
“持续时间”=>$duration\u time[$j],
“年费用”=>年费用[$j],
“费用来源”=>$expenses\u来源[$j],
“备注”=>$remark[$j],
'userid'=>this->m\u auth->get\u user\u id(),
'u_rec_id'=>$u_rec_id,
“序列号”=>$serial,
“regdate”=>date('Y-m-dh:m:s')
);
数组推送($all\u数组,$this->ci\u表单);
}
}
}

还是这样比较好 直接从循环内的会话获取数据

$user_name                  = $this->input->post('user_name');
  $organization_name          = $this->input->post('organization_name');
  $location                   = $this->input->post('location');
  $duration_time              = $this->input->post('duration_time');
  $yearly_expences            = $this->input->post('yearly_expences');
  $expences_source            = $this->input->post('expences_source');
  $remark                     = $this->input->post('remark');


  $all_array = array();

  if( $user_name ) {
     if( is_array( $user_name ) ) {

        for( $j = 0 ; $j < count( $user_name ) ; $j++ ) {
            $this ->ci_form = array(
                'user_name'         => $user_name[$j],
                'organization_name' => $organization_name[$j],
                'location'          => $location[$j],
                'duration_time'     => $duration_time[$j],
                'yearly_expences'   => $yearly_expences[$j],
                'expences_source'   => $expences_source[$j],
                'remark'            => $remark[$j],
                'userid'            => $this->m_auth->get_user_id(),
                'u_rec_id'          => $this->session->userdata('rec_id'),
                'serial'            => $this->session->userdata('serial'),
                'regdate'           => date('Y-m-d H:m:s')
            );
            array_push( $all_array, $this->ci_form );
         }           
       }
    }
$user\u name=$this->input->post('user\u name');
$organization\u name=$this->input->post('organization\u name');
$location=$this->input->post('location');
$duration\u time=$this->input->post('duration\u time');
$year_expenses=$this->input->post('year_expenses');
$expenses\u source=$this->input->post('expenses\u source');
$remark=$this->input->post('remark');
$all_array=array();
如果($user\u name){
if(is_数组($user_name)){
对于($j=0;$jci_form=array(
“用户名”=>$user\u name[$j],
“组织机构名称”=>$organization\u name[$j],
“位置”=>$location[$j],
“持续时间”=>$duration\u time[$j],
“年费用”=>年费用[$j],
“费用来源”=>$expenses\u来源[$j],
“备注”=>$remark[$j],
'userid'=>this->m\u auth->get\u user\u id(),
'u_rec_id'=>$this->session->userdata('rec_id'),
“串行”=>$this->session->userdata('serial'),
“regdate”=>date('Y-m-dh:m:s')
);
数组推送($all\u数组,$this->ci\u表单);
}           
}
}

使用第一种方法并保存一些函数调用:

$user_name                  = $this->input->post('user_name');
$organization_name          = $this->input->post('organization_name');
$location                   = $this->input->post('location');
$duration_time              = $this->input->post('duration_time');
$yearly_expences            = $this->input->post('yearly_expences');
$expences_source            = $this->input->post('expences_source');
$remark                     = $this->input->post('remark');

$u_rec_id = $this->session->userdata('rec_id');
$serial   = $this->session->userdata('serial');

$all_array = array();

foreach ((array)$user_name as $j=>$each) {
    $this ->ci_form = array(
        'user_name'         => $user_name[$j],
        'organization_name' => $organization_name[$j],
        'location'          => $location[$j],
        'duration_time'     => $duration_time[$j],
        'yearly_expences'   => $yearly_expences[$j],
        'expences_source'   => $expences_source[$j],
        'remark'            => $remark[$j],
        'userid'            => $this->m_auth->get_user_id(),
        'u_rec_id'          => $u_rec_id,
        'serial'            => $serial,
        'regdate'           => date('Y-m-d H:m:s')
    );

    array_push($all_array, $this->ci_form);
}

很明显,如果在循环中避免会话检索过程,它会更快。但这并不重要。