PHP array_merge() Function
The array_merge function in PHP is a type of function that is used to merge or combine one or many arrays into one single array. This function is used when there are two or more arrays with each array having a different key and we want to display them as one single array. It means that if there are two arrays array A and array B and none of the elements of these two arrays have the same key then using this array_merge function we can combine both arrays and it will be displayed as AB. You can also assign one array to this function.
Example: In this example, we have declared two different arrays with different keys and we have combined them using the array_merge() Function.
PHP
<?php $a1 = array ( "Mumbai" , "Nashik" ); $a2 = array ( "Nagpur" , "Pune" ); print_r( array_merge ( $a1 , $a2 )); ?> |
Array ( [0] => Mumbai [1] => Nashik [2] => Nagpur [3] => Pune )
What is the differences between array_merge() and array_merge_recursive() functions in PHP ?
In this article, we will see the array_merge() and array_merge_recursive() functions, along with understanding their basic implementation, & the differences between them.
Both the array_merge() Function and array_merge_recursive() function can be used to combine multiple arrays into a single array.
Table of Content
- PHP array_merge() Function
- PHP array_merge_recursive() Function
- Difference between array_merge() and array_merge_recursive() Functions