Be ready to surprise like this one.
array_merge renumbers numeric keys even if key is as string.
keys '1' & '2' will be updated to 0 & 1, but '1.1' & '1.2' remain the same, but they are numeric too (is_numeric('1.1') -> true)
It's better to use '+' operator or to have your own implementation for array_merge.
<?php
$x1
= array (
'1'
=>
'Value 1'
,
'1.1'
=>
'Value 1.1'
,
);
$x2
= array (
'2'
=>
'Value 2'
,
'2.1'
=>
'Value 2.1'
,
);
$x3
=
array_merge
(
$x1
,
$x2
);
echo
'<pre>NOT as expected: '
.
print_r
(
$x3
,
true
) .
'</pre>'
;
$x3
=
$x1
+
$x2
;
echo
'<pre>As expected: '
.
print_r
(
$x3
,
true
) .
'</pre>'
;
?>
NOT as expected: Array
(
[0] => Value 1
[1.1] => Value 1.1
[1] => Value 2
[2.1] => Value 2.1
)
As expected: Array
(
[1] => Value 1
[1.1] => Value 1.1
[2] => Value 2
[2.1] => Value 2.1
)