hellosheikh
hellosheikh

Reputation: 3015

save data in separate array in each iteration

$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);

//here i want to declare an another array which saves the data of every iteration..because i dont want override the data

sorry i am week in arrays.. and do tell me how can i then print the array ...if i want to display the 1st iteration result in my view page

Upvotes: 0

Views: 170

Answers (1)

Ziemo
Ziemo

Reputation: 991

If you just want to add new element to the array without deleting its content you can do that just like that:

$recent[] = 'new_string1';

or if you have more elements:

array_push($recent, 'new_string1', 'new_string2');

But in the future, please read manual: http://php.net/manual/en/function.array-push.php

Upvotes: 1

Related Questions