lilmer Posted October 29, 2013 Share Posted October 29, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/283392-insert-new-array-data-inside-a-stdclass-object/ Share on other sites More sharing options...
objnoob Posted October 29, 2013 Share Posted October 29, 2013 What is your error? Quote Link to comment https://forums.phpfreaks.com/topic/283392-insert-new-array-data-inside-a-stdclass-object/#findComment-1455986 Share on other sites More sharing options...
Solution objnoob Posted October 29, 2013 Solution Share Posted October 29, 2013 (edited) Anyways, you should try $a = (array) $array[$key]; $a['stared'] = 1; $array[$key] = (object) $a; Edited October 29, 2013 by objnoob Quote Link to comment https://forums.phpfreaks.com/topic/283392-insert-new-array-data-inside-a-stdclass-object/#findComment-1455987 Share on other sites More sharing options...
lilmer Posted October 29, 2013 Author Share Posted October 29, 2013 Nice, thanks it works. Quote Link to comment https://forums.phpfreaks.com/topic/283392-insert-new-array-data-inside-a-stdclass-object/#findComment-1455990 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.