Php, method: php to merge arrays in two ways, the specific method for me to slowly: 1. the array_merge () function merges arrays as follows: u, order & gt; uid, limit & gt; 5); $ barray (where & gt; u, order & gt; uiddesc,); $ carray_m there are two ways to merge arrays in php. the specific method is as follows:
1. the array_merge () function merges arrays.
The example is as follows:
'uid=1', 'order' => 'uid', 'limit' => '5'); $b = array( 'where' => 'uid=2', 'order' => 'uid desc', ); $c = array_merge($a,$b);print_r($c);$d = array_merge($b,$a);print_r($d);
The output result is as follows:
Array ([where] => uid = 2 [order] => uid desc [limit] => 5)
Array ([where] => uid = 1 [order] => uid [limit] => 5)
Note the where and uid fields. these two fields are the common fields in the $ a and $ B arrays. what can be summed up by the differences between the two field values in the results?
When you use array_merge to merge arrays, if duplicate keys exist, the key value is the same as the key value of the field in the second parameter of the function.
2. operator + merge array
The specific example is as follows:
'uid=1', 'order' => 'uid', 'limit' => '5'); $b = array( 'where' => 'uid=2', 'order' => 'uid desc', ); $c = $a+$b;print_r($c);$d = $b+$a;print_r($d);
The output result is as follows:
Array ([where] => uid = 1 [order] => uid [limit] => 5)
Array ([where] => uid = 2 [order] => uid desc [limit] => 5)
As shown above, we still pay attention to the values of the where and order Fields. what conclusions can we draw?
When you use the operator + to merge arrays, the duplicate key has the same key value as the value in the array with the key at the beginning.
Summary: There are two ways to merge arrays in php: one is to use the php built-in function array_merge, and the other is to use the operator +, the difference is that when the array to be merged has the same key value, when array_merge is merged, the key value of this key is the same as the key value in the latter, that is, it will overwrite; when the operator + number is used, the key value of the key is the same as the key value of the former, that is, the existing key value is not executed.
The above two methods of merging arrays in php are similarities and differences. thank you for your reading.
'). AddClass ('pre-numbering '). hide (); $ (this ). addClass ('Has-numbering '). parent (). append ($ numbering); for (I = 1; I <= lines; I ++) {$ numbering. append ($ ('
'). Text (I) ;}; $ numbering. fadeIn (1700) ;}) ;}; script
The above describes how to merge arrays in php, including php and methods. I hope my friends who are interested in PHP will be helpful.