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.
- Array_intersect()
- Array_intersect_assoc()
Array_diff ()
- 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!