Relieving you from PHP array merging troubles_PHP Tutorial

WBOY
Release: 2016-07-15 13:27:17
Original
829 people have browsed it

PHP is still relatively commonly used, so I studied PHP array merging and shared it with you here. I hope it will be useful to everyone. This section mainly studies other issues about arrays in PHP, including PHP array merging, decomposition, etc.

If you have not studied the previous three articles, it is recommended to read them: PHP array sorting. For arrays, we can perform operations such as addition and subtraction. First, let's look at PHP array merging - array_merge(), + and other "operators". 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().

array_merge_recursive() Usage

array_merge_recursive() can merge two or more arrays together to form a combined array, array_merge_recursive() and array_merge() ) The difference before 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 the previous Key/value pairs that exist.

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.

Split the array

Since it can be merged, it is natural to split the array. 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.

<ol class="dp-xml">
<li class="alt"><span><span>Array_intersect()  </span></span></li>
<li class=""><span>Array_intersect_assoc() </span></li>
</ol>
Copy after login

Difference set of associative arrays Array_diff()

<ol class="dp-xml"><li class="alt"><span><span>Array_diff_assoc() </span></span></li></ol>
Copy after login

Summary: In this chapter we have studied PHP array issues, 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/446528.htmlTechArticlePHP is still relatively commonly used, so I studied PHP array merging and shared it with you here. Hope it's useful to everyone. This section focuses on learning other questions about arrays in PHP...
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!