From 3c7d5d1fdab73a803595c86b2f67e00d48457505 Mon Sep 17 00:00:00 2001 From: Jan Lehnardt Date: Tue, 4 May 2004 19:01:46 +0000 Subject: [PATCH] - reflect the fact, that merging a single array is possible and added a corresponding example. Thanks to vmx. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@157951 c90b9560-bf6c-de11-be94-00142212c4b1 --- reference/array/functions/array-merge.xml | 50 +++++++++++++++++++++-- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/reference/array/functions/array-merge.xml b/reference/array/functions/array-merge.xml index 46fc9dcec3..e6f6be554c 100644 --- a/reference/array/functions/array-merge.xml +++ b/reference/array/functions/array-merge.xml @@ -1,21 +1,21 @@ - + array_merge - Merge two or more arrays + Merge one or more arrays Description arrayarray_merge arrayarray1 - arrayarray2 + arrayarray2 array... - array_merge merges the elements of two or + array_merge merges the elements of one or more arrays together so that the values of one are appended to the end of the previous one. It returns the resulting array. @@ -26,6 +26,11 @@ role="strong">not overwrite the original value, but will be appended. + + If only one array is given and the array is numerically indexed, the + keys get reindexed in a continuous way. For associative arrays, duplicate + entries will be merged into the last one. See example three for details. + <function>array_merge</function> example @@ -103,6 +108,43 @@ Array ( [1] => data ) +]]> + + + + <function>array_merge</function> example + + "jay", 1 => "bob", 2 => "randal", 3 => "dante"); +$array_two = array("jay" => "bob", "randal" => "dante", "jay" => "jason"); + +unset($array_one[2]); + +$result_one = array_merge($array_one); +$result_two = array_merge($array_two); + +print_r($result_one); +print_r($result_two); +?> +]]> + + + The output is: + + + jay + [1] => bob + [2] => dante +) +Array +( + [jay] => jason + [randal] => dante +) ]]>