Example 2. Simple array_merge() example
<?php
$array1 = array();
$array2 = array(1 => "data");
$result = array_merge($array1, $array2);
?>
Don't forget that numeric keys will be renumbered!
Array
(
[0] => data
)
If you want to completely preserve the arrays and just
want to append them to each other, use the + operator:
<?php
$array1 = array();
$array2 = array(1 => "data");
$result = $array1 + $array2;
?>
The numeric key will be preserved and thus the association
remains.
Array
(
[1] => data
)
Note: Shared keys will be overwritten on a first-come first-served
basis.
See also array_merge_recursive(), array_combine() and array
operators.
|