PHP uses Array_merge to rearrange array subscript methods, Array_merge array
This example describes how PHP rearranges array subscripts using Array_merge. Share to everyone for your reference. Specific as follows:
A array_unique was used to remove the repetition of an array, but the subscript was found to retain the subscript of the original array, but PHP uses a for loop to order the subscript neatly, so looking for a way to rearrange the array subscript array_merge can solve this problem
The Array_merge () function merges two or more arrays into an array.
If the key name is duplicated, the key's key value is the value corresponding to the last key name (followed by overwriting the previous one). If the array is a numeric index, the key name is re-indexed in a sequential manner.
Note: If you only enter an array into the Array_merge () function and the key name is an integer, the function returns a new array with an integer key name, with the key name re-indexed starting at 0. (see Example 2)
Grammar:
Array_merge (Array1,array2,array3 ...)
Parameters |
Description |
Array1 |
Necessary. The first array entered. |
Array2 |
Necessary. The second array entered. |
Array3 |
Optional. Multiple input arrays that can be specified. |
Example 1
<?php$a1=array ("A" = "Horse", "b" = "Dog"), $a 2=array ("c" = "Cow", "B" and "Cat");p Rint_r (Array_merge ($ A1, $a 2));? >
Output:
Array ([A] = Horse [b] = Cat [c] = Cow)
Example 2
Use only one array parameter:
<?php$a=array (3=> "Horse",4=> "Dog");p Rint_r (Array_merge ($a));? >
Output:
Array ([0] = Horse [1] = Dog)
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/1036257.html www.bkjia.com true http://www.bkjia.com/PHPjc/1036257.html techarticle PHP uses Array_merge to rearrange array subscript methods, Array_merge Array This example describes how PHP uses Array_merge to rearrange array subscripts. Share to everyone for your reference. ...