Home > Backend Development > PHP Tutorial > Detailed explanation of PHP array merging and splitting_PHP tutorial

Detailed explanation of PHP array merging and splitting_PHP tutorial

WBOY
Release: 2016-07-15 13:29:25
Original
1026 people have browsed it

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!


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446360.htmlTechArticleCurrently, if you just want to append an array to the back of another array, you can use "+". This is the same as when we do addition: $a=$array1+$array2; only the special explanation "...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template