Home >Daily Programming >PHP Knowledge >How to merge arrays in PHP
This article mainly introduces how PHP implements the merger of two arrays, and the value of one array is the subscript, and the value of the other array is the corresponding value.
PHP merges ordinary arrays, I believe everyone has mastered it. But for novice friends, when merging two arrays, the subscript and value of the new array are the values of the two arrays before merging respectively. The processing of this kind of array merging may be a little difficult. In fact, it is also very easy to implement.
Below we will explain it to you with simple code examples.
The code is as follows:
<?php $arr = ['姓名','年龄','性别' ]; $arr2 = ['王小二',24,'男']; var_dump(array_combine($arr,$arr2));
The result is as shown below:
array_combine function means creating an array, using the value of one array as its key name and the value of another array as its value.
array_combine syntax is as follows:
array array_combine ( array $keys , array $values )Returns an array, in which the parameters are represented respectively, using the value from the keys array as the key name, and the value from the values array as the corresponding value. This article is a detailed introduction to PHP merging arrays. It is very easy to understand. I hope it will be helpful to friends in need!
The above is the detailed content of How to merge arrays in PHP. For more information, please follow other related articles on the PHP Chinese website!