Hello everyone. I have an object, and I have a new value which I need to add to this object, but not just to the end of it, that would be no problem accomplishing. What I need to do is add this value to a new node on a specific index.
Ok so here's the object.
[object]=>{
["a"]=> "value"
["b"]=> "value"
["c"]=> "value"
["d"]=> "value"
}
Then I have this fifth value that I now need to add to index 1, or as it's named in this example "b". Like this.
[object]=>{
["a"]=> "value"
["e"]=> "fifth value"
["b"]=> "value"
["c"]=> "value"
["d"]=> "value"
}
So the question remains, is there a smart way to do this or do I have to split them up and make them into arrays and merge them as arrays then assign them to a new object explicitly telling it to be an object?
Like this.
$object = (object)array_merge((array)$first, (array)$second);
I feel that there must be a better way to handle this, with only objects.
Thank you for your time.