I want to insert $my_object into an array of objects, for example between the fourth and fifth element of $my_array_of_objects.
$my_object = myObject ();
$my_array_of_objects = Array (
[1] => Object ()
[2] => Object ()
[3] => Object ()
[4] => Object ()
[5] => Object ()
)
// to something like this :
$my_array_of_objects = Array (
[1] => Object ()
[2] => Object ()
[3] => Object ()
[4] => Object ()
[5] => myObject () //the position i want to insert my object
[6] => Object ()
)
I try this but it dosen't work.
array_splice($my_array_of_objects, 0, 4, $my_object);
I know how to add $my_object at the end of the array but not at any position. Any help would be greatly appreciated!
Thanks!