PHP Merge Array We can use the Array_merge () function, and the Array_merge () function returns a federated array. The resulting array begins with the first input array parameter, appended in the order in which the following array parameters appear. In the form of:
Array Array_merge (array array1 array2...,arrayn)
The following is an example of a php merge array:
1
2$fruits = Array ("Apple", "banana", "pear");
3$numbered = Array ("1", "2", "3");
4$cards = Array_merge ($fruits, $numbered);
5print_r ($cards);
6//Output Result:
7//Array ([0] => Apple [1] => banana [2] => pear [3] => 1 [4] => 2 [5] => 3)
8?>
Append the array with PHP, use array_merge_recursive (), combine two numbers together, note that the Array_merge () function is not the same, Array_merge () of the two array with duplicates will be overwritten, and Array_ Merge_recursive () is not. Array_merge_recursive () Syntax:
Array array_merge_recursive (array Array1,array array2[...,array Arrayn])
The following is an example of a PHP append array:
1
2$fruit1 = Array ("Apple" => "red", "banana" => "yellow");
3$fruit2 = Array ("pear" => "yellow", "apple" => "green");
4$result = array_merge_recursive ($fruit 1, $fruit 2);
5print_r ($result);
6//Output Result:
7//Array ([Apple] => Array ([0] => red [1] => green) [Banana] => yellow [pear] => yellow)
8?>
Now Apple points to an array of indices consisting of two color values.