$var
is an array:
Array (
[0] => stdClass Object ( [ID] => 113 [title] => text )
[1] => stdClass Object ( [ID] => 114 [title] => text text text )
[2] => stdClass Object ( [ID] => 115 [title] => text text )
[3] => stdClass Object ( [ID] => 116 [title] => text )
)
Want to update it in two steps:
[ID]
of each object and throw its value to position counter (I mean [0], [1], [2], [3]
)[ID]
after throwingFinally, updated array ($new_var
) should look like:
Array (
[113] => stdClass Object ( [title] => text )
[114] => stdClass Object ( [title] => text text text )
[115] => stdClass Object ( [title] => text text )
[116] => stdClass Object ( [title] => text )
)
How to do this?
Thanks.
$new_array = array();
foreach ($var as $object)
{
$temp_object = clone $object;
unset($temp_object->id);
$new_array[$object->id] = $temp_object;
}
I'm making the assumption that there is more in your objects and you just want to remove ID. If you just want the title, you don't need to clone to the object and can just set $new_array[$object->id] = $object->title
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With