Jump to content

Insert new array data inside a stdClass Object


lilmer

Recommended Posts

I've got this sample of array data

Array
(
    [0] => stdClass Object
        (
            [fileid] => 333
            [filename] => Douglas           
            [datecreated] => 2013-10-25 09:53:27
            [datemodified] => 2013-10-25 09:53:27
            [fileAccess] => 1
            [user_id] => 70          
        )

    [1] => stdClass Object
        (
            [fileid] => 326
            [filename] => Yeah baby           
            [datecreated] => 2013-10-24 09:02:05
            [datemodified] => 2013-10-24 09:02:05
            [fileAccess] => 1
            [user_id] => 70                     
        )

    [2] => stdClass Object
        (
            [fileid] => 329
            [filename] => UNTITLED File
            [datecreated] => 2013-10-25 07:14:53
            [datemodified] => 2013-10-25 07:14:53
            [fileAccess] => 1
            [user_id] => 70            
        )

    [3] => stdClass Object
        (
            [fileid] => 330
            [filename] => UNTITLED FILE
            [datecreated] => 2013-10-25 07:17:55
            [datemodified] => 2013-10-25 07:17:55
            [fileAccess] => 1
            [user_id] => 70               
        )

    [4] => stdClass Object
        (
            [fileid] => 332
            [filename] => UNTITLED FILE
            [datecreated] => 2013-10-25 08:42:35
            [datemodified] => 2013-10-25 08:42:35
            [fileAccess] => 1
            [user_id] => 70
            [statuss] => 1
        )

)

and by fileid I would like to check if the fileid is also existing on the other mysql. .

 

so I did this 

foreach($array as $key => $row){
   
   $query = $this->model->get($row->fileid); 
   //query return true or false;
   
   if($query){
     $array[$key]['stared'] = 1;
   }  
}

but it gives an error. How will I going to insert a new variable on the current array loop if the fileid is existing. 

 

e.g.

 [4] => stdClass Object
        (
            [fileid] => 332
            [filename] => UNTITLED FILE
            [datecreated] => 2013-10-25 08:42:35
            [datemodified] => 2013-10-25 08:42:35
            [fileAccess] => 1
            [user_id] => 70
            [statuss] => 1
            [stared] => 1 //IF STARED RETURN TRUE
        )

Thanks

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.