Php array merge
From w3cyberlearnings
Contents |
PHP function array_merge
This function merges two or more arrays into a new array. Duplicate array will be overrided.
Syntax array_merge
- array1: array 1 input
- array2: array 2 input
- array3: array 3 input
array_merge(array1, array2, array3, ...);
Example 1
<?php $name1 = array( 'Enzo', 'Harlow Olivia Calliope', 'Jamison Leon'); $name2 = array( 'Romeo', 'Ronan', 'Benjamin', 'Wolfgang'); $name3 = array( 'Romeo Jon', 'Stephanie Rose'); $names = array_merge($name1, $name2, $name3); foreach ($names as $n) { echo $n; echo '<br/>'; } ?>
Output
Enzo Harlow Olivia Calliope Jamison Leon Romeo Ronan Benjamin Wolfgang Romeo Jon Stephanie Rose
Example 2
<?php $name1 = array( 'Enzo' => 12, 'Harlow Olivia Calliope' => 3, 'Jamison Leon' => 9); $name2 = array( 'Romeo' => 3, 'Ronan' => 13, 'Benjamin' => 5, 'Wolfgang' => 8); $name3 = array( 'Romeo Jon' => 7, 'Stephanie Rose' => 8); $names = array_merge($name1, $name2, $name3); print_r($names); ?>
Output
Array ( [Enzo] => 12 [Harlow Olivia Calliope] => 3 [Jamison Leon] => 9 [Romeo] => 3 [Ronan] => 13 [Benjamin] => 5 [Wolfgang] => 8 [Romeo Jon] => 7 [Stephanie Rose] => 8 )
Related Links
- array_change_key_case
- array_chunk
- array_combine
- array_count_values
- array_diff_assoc
- array_diff_key
- array_diff_uassoc
- array_diff_ukey
- array_diff
- array_fill_keys
- array_fill
- array_filter
- array_flip
- array_intersect_assoc
- array_intersect_key
- array_intersect_uassoc
- array_intersect_ukey
- array_intersect
- array_key_ exists
- array_keys