$php -a
php > $data1 = ['tag' => 'div', 'classes' => [1,2,3]];
php > $data2 = ['tag' => 'section', 'classes' => [2,3,4,5,6]];
php > $result = array_merge_recursive($data1, $data2);
php > print_r($result);
Array
(
[tag] => Array
(
[0] => div
[1] => section
)
[classes] => Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 2
[4] => 3
[5] => 4
[6] => 5
[7] => 6
)
)
So as describes in the Docs:
If the input arrays have the same string keys, then the values for these keys are merged together into an array[…]
Is there a existing function within PHP that basically does the same, but without merging the same keys into an array, so that the values are overridden and the key kept?
In this case I would like to have that result:
Array
(
[tag] => section
[classes] => Array
(
[0] => 1
[1] => 2
[2] => 3
[5] => 4
[6] => 5
[7] => 6
)
)
In regards to the comment of @JustOnUnderMillions:
Yes I wonder, that is not what I would expect of such a function, I would expect a result as I am looking for.