How to handle a key (index
) of a parent array? I'm getting numeric keys, but I need an index
as a key.
Example.
Sample input:
$arrayFirst = [
"index" => ['a' => '1'],
['a' => '2']
];
$arraySecond = [
"index" => ['b' => '1'],
['b' => '2']
];
My code:
var_export(
array_map(
function(...$items) {
return array_merge(...$items);
},
$arrayFirst,
$arraySecond
)
);
Incorrect/Current output:
array (
0 =>
array (
'a' => '1',
'b' => '1',
),
1 =>
array (
'a' => '2',
'b' => '2',
),
)
Desired output:
array (
'index' =>
array (
'a' => '1',
'b' => '1',
),
0 =>
array (
'a' => '2',
'b' => '2',
),
)