The PHP function array_merge () is used to parse the array. If the original array itself has been re-sorted, you must re-sort the new array after the array is merged. In the following example, we mayIf the original array itself has been re-sorted, after the array is merged, you must re-sort the generated new array. The following example describes how to use the PHP function array_merge:
- <? /* First create the first array */
-
- $FruitArray=Array("Apple", "orange", "banana", "Peach", "pear ");
-
- /* Create the second array */
-
- $VegArray=Array("Carrot", "green beans", "asparagus", "artichoke", "corn ");
-
- /* Now use the array_merge () function to combine the two arrays into a new array */
-
- $GoodfoodArray=Array_merge($ FruitArray, $ vegArray );
-
- /* Finally, the keys and values of all elements in the merged new array are displayed on the webpage */
-
- While (list ($ key, $ value) = each ($ goodfoodArray )){
-
- Echo "$ key: $ value <br> ";
-
- }
-
- ?>
The result is as follows:
0: apple
1: orange
2: banana
3: Peach
4: pear
5: carrot
6: green beans
7: asparagus
8: artichoke
9: corn
The usage of the PHP function array_merge () in array merging is shown above.
If the original array itself has been re-sorted, after the array is merged, you must re-sort the generated new array. The following example...