I want insert one array to another associative array at specific position, but for me the array_splice doesn't work. I want do this:
$example = [
'first' => 'element',
'second' => 'element'];
$example[] = [
'third' => 'element',
'fourth' => 'element'];
Now we have a associative array with inside with two another array. And I want to insert on another array in it, for example between it. It is important, i want to insert to a specific index.
$insert[] = [
'insert_first' => 'element',
'insert_second' => 'element'];
//I made before it:
$index = 1;
array_splice($example, $index, 0, $insert); //but it doesn't work :(
I want the following result:
array(
[0] => array(
'first' => 'element',
'second' => 'element'
)
[1] => array(
'insert_first' => 'element',
'insert_second' => 'element'
)
[2] => array(
'third' => 'element',
'fourth' => 'element'
)
)
Can somebody help me how can i made it?
Thank, Balázs from Hungary.
$example
, it should be$example[]
if you want the desired result