Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.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
Arrays 在每次迭代中以单独的数组保存数据 $this->layout='defaultall'; $id=$this->Auth->user('idUser'); $data=$this->Contact->find('all',数组( 'conditions'=>array('Contact.User_id'=>$id)); $this->set('contacts',$data); $this->loadModel('Calllog'); /*对于($i=1;$iCalllog->find('all'), 数组('order'=>'Calllog.idCallLog DESC', “限制”=>1, “条件”=>array('Calllog.mobileNo'=>array($mobile、$work、$home), 'Calllog.User_id'=>$id ))); //这里是要声明的数组 $this->set('a',$recent);_Arrays_Cakephp_For Loop_Foreach_Cakephp 2.0 - Fatal编程技术网

Arrays 在每次迭代中以单独的数组保存数据 $this->layout='defaultall'; $id=$this->Auth->user('idUser'); $data=$this->Contact->find('all',数组( 'conditions'=>array('Contact.User_id'=>$id)); $this->set('contacts',$data); $this->loadModel('Calllog'); /*对于($i=1;$iCalllog->find('all'), 数组('order'=>'Calllog.idCallLog DESC', “限制”=>1, “条件”=>array('Calllog.mobileNo'=>array($mobile、$work、$home), 'Calllog.User_id'=>$id ))); //这里是要声明的数组 $this->set('a',$recent);

Arrays 在每次迭代中以单独的数组保存数据 $this->layout='defaultall'; $id=$this->Auth->user('idUser'); $data=$this->Contact->find('all',数组( 'conditions'=>array('Contact.User_id'=>$id)); $this->set('contacts',$data); $this->loadModel('Calllog'); /*对于($i=1;$iCalllog->find('all'), 数组('order'=>'Calllog.idCallLog DESC', “限制”=>1, “条件”=>array('Calllog.mobileNo'=>array($mobile、$work、$home), 'Calllog.User_id'=>$id ))); //这里是要声明的数组 $this->set('a',$recent);,arrays,cakephp,for-loop,foreach,cakephp-2.0,Arrays,Cakephp,For Loop,Foreach,Cakephp 2.0,//这里我想声明另一个数组,它保存每次迭代的数据。因为我不想覆盖数据 很抱歉,我在阵列中工作了一周。请告诉我如何打印阵列…如果我想在我的查看页面中显示第一次迭代结果如果您只想向阵列添加新元素而不删除其内容,您可以这样做: $this->layout='defaultall'; $id = $this->Auth->user('idUser'); $data= $this->Contact->find('all',array( 'co

//这里我想声明另一个数组,它保存每次迭代的数据。因为我不想覆盖数据


很抱歉,我在阵列中工作了一周。请告诉我如何打印阵列…如果我想在我的查看页面中显示第一次迭代结果

如果您只想向阵列添加新元素而不删除其内容,您可以这样做:

$this->layout='defaultall';

    $id = $this->Auth->user('idUser');
    $data= $this->Contact->find('all',array(
        'conditions' => array('Contact.User_id' => $id)));
          $this->set('contacts',$data);


 $this->loadModel('Calllog');

  /*  for($i=1; $i < 2; $i++)
    {
        $mobile =$data[$i]['Contact']["mobileNo"];
        $work =$data[$i]['Contact']["workNo"];
        $home =$data[$i]['Contact']["homeNo"];*/



   for($data as $datas){

      $mobile=  $datas['Contact']['mobileNo'];
      $home=  $datas['Contact']['homeNo'];
      $work=  $datas['Contact']['workNo'];




      $recent=$this->Calllog->find('all',
          array('order'=>'Calllog.idCallLog DESC',
              'limit' => 1,
              'conditions' => array('Calllog.mobileNo' => array($mobile,$work,$home ),
                  'Calllog.User_id' => $id


              )));

      //here array want to declare


      $this->set('a',$recent);
或者,如果您有更多元素:

$recent[] = 'new_string1';

但将来,请阅读手册:

使用“$this->{Model}->create()'您想将每个迭代的数据保存到同一级别的
$recent
数组中,还是每个迭代都应该在
$recent
数组中的单独数组中?我想将最近的每个迭代保存到单独数组中..因此,如果我想显示第一次迭代的结果,我可以在我的视图页面中显示它make$recent to$recent[]。这将包含循环的所有记录。稍后您可以在视图中迭代此循环
array_push($recent, 'new_string1', 'new_string2');