Currently for If you just want to append an array to another array, you can use "+". This is the same as when we do addition: $a=$array1+$array2; only the special "+" will cause the numeric key name to be retained and the original association to remain unchanged, while array_merge() does not have this feature - it will Re-index. In addition, array_merge() also has a "sister" function array_merge_recursive().
Usage of array_merge_recursive() between PHP array merging and splitting
array_merge_recursive() can merge two or more arrays together to form a joint 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()) will merge the two values into a new function, while array_merge() Will simply overwrite previously existing key/value pairs.
How to use Array_combine()
In the help manual, we learned that Array_combine() will get a new array, only a few of the original arrays They must be the same size and cannot be empty. Not much else to say, just check the manual. Make enough food and clothing by yourself.
PHP array merging and splitting Array splitting
Since arrays can be merged, arrays can naturally be split. Array_slice() and other functions can complete the corresponding tasks, please check the help manual
Intersection of arrays
This part only introduces some functions, as for the usage, it is very complicated It’s simple, I don’t want to say more so as not to complicate a simple thing.
Array_intersect() Array_intersect_assoc()
Difference set of associative arrays Array_diff()
Array_diff_assoc()
Summary: In In this chapter, we learned about PHP array merging and splitting, from basic array creation to array sorting. Among them, the sorting of arrays is a key point, which can be strengthened in the application. This chapter only provides a brief introduction to some knowledge. When operating PHP arrays, PHP provides us with a large number of functions, but these functions cannot all meet our needs. Therefore, this chapter also discusses issues such as custom sorting functions, but it is not profound enough. I hope to do more in the future. More comprehensive and profound learning!