I want to add a new index to my array of objects and be able to loop and retrieve that new index added.
Currently my array of objects is the following:
Array ([0] =>
stdClass Object ([id] => 4 [date] => 2014-09-08 10:18:10 [status] => 1)
)
So, to loop it I just do:
foreach($content as $item){
echo $item->id;
}
But, for some reasons, I need to push a new element to my array:
$item = $data['content']; // $data holds the content above
$clone = array();
foreach($item as $row){
if($row->status == 1){
array_push($clone, $row, array("delete" => TRUE));
}else{
array_push($clone, $row, array("delete" => FALSE));
}
}
$item = $clone;
And the output is this:
Array ( [0] =>
stdClass Object ([id] => 4 [date] => 2014-09-08 10:18:10 [status] => 1) [1] => Array ( [delete] => 1)
)
But instead I would like something like
Array ( [0] =>
stdClass Object ([id] => 4 [date] => 2014-09-08 10:18:10 [status] => 1 [delete] => 1)
)
I also tried:
$item[] = (object) array("delete" => FALSE);
But the problem persists.