Php method for merging arrays php method for calling class php method for calling parent class php method for learning

Source: Internet
Author: User
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.

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.