PHP array_merge_recursive() Function
In this chapter you will learn:
- Definition for PHP array_merge_recursive() Function
- Syntax for PHP array_merge_recursive() Function
- Parameter for PHP array_merge_recursive() Function
- Example - Merge two array recursively
Definition
The array_merge_recursive() function merges one ore more arrays into one array. array_merge_recursive() function makes the values as an array for duplicated keys.
If there is no duplicates the array_merge_recursive() function will behave the same as the array_merge() function.
Syntax
PHP array_merge_recursive() Function has the following syntax.
array_merge_recursive(array1,array2,array3...)
Parameter
Parameter | Is Required | Description |
---|---|---|
array1 | Required. | Array to merge |
array2 | Optional. | Array to merge |
array3,... | Optional. | Array to merge |
Example
Merge two array recursively
<?php// j ava2 s. c o m
$a1=array("a"=>"A","b"=>"B","j"=>"java2s.com");
$a2=array("c"=>"C","B"=>"b");
print_r(array_merge_recursive($a1,$a2));
?>
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
- Definition for PHP array_multisort() Function
- Syntax for PHP array_multisort() Function
- Parameter for PHP array_multisort() Function
- Example - Using sorting parameters
- Example - Merge two arrays and sort them as numbers, in descending order
- Example - array_multisort keeps the relationship between arrays
- Example - Use array_multisort() to sort multidimensional arrays
Home » PHP Tutorial » PHP Array Functions