Free you from worries about PHP array Merging

Source: Internet
Author: User

PHP is still quite common, So I studied PHP array merging and share it with you here. I hope it will be useful to you. This section describes other questions about arrays in PHP, including PHP array merging and decomposition.

If you have not studied the previous three articles, we suggest you go to PHP array sorting. we can add or subtract arrays. First, let's look at the PHP array merging-array_merge (), + and other "operators ". If you only need to append the array to the end of another array, you can use "+. This is the same as our addition: $ a = $ array1 + $ array2; only the special note "+" will keep the number key names so that the original association remains unchanged, while the array_merge () this feature is not available-it will re-index. In addition, array_merge () has a "sister" function, array_merge_recursive ().

Array_merge_recursive () Usage

Array_merge_recursive () can combine two or more numbers to form a combined array. The difference between array_merge_recursive () and array_merge () is: when an array already exists in the result array, this function (array_merge_recursive () combines the two values into a new function, while array_merge () the existing key/value pairs are overwritten.

How to Use Array_combine ()

In the help manual, we learned that Array_combine () will get a new array, which must be of the same size but cannot be empty. I will not talk about anything else. Check the manual. Self-help clothes and food.

Split an array

Since it can be merged, You can naturally split the array. Array_slice () and other functions can complete the corresponding tasks. Please refer to the help manual.

Array Intersection

This part only introduces some functions. As for the usage, it is very simple and I don't want to talk much about it, so as to avoid complicated simple things.

 
 
  1. Array_intersect()  
  2. Array_intersect_assoc() 

Array_diff ()

 
 
  1. Array_diff_assoc() 

Summary: In this chapter, we have learned about PHP arrays, from basic array creation to array sorting. The sorting of arrays is a key point, which can be enhanced in the application. This chapter briefly introduces some knowledge. When operating on PHP arrays, PHP provides a large number of functions for us, but these functions cannot meet our needs. Therefore, this chapter also discusses custom sorting functions, it's just not profound enough. I hope to learn more comprehensively and profoundly in the future!


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.