"男","姓名"=>"不是女人");$array4=array("性别"=>"不知道&quo"/> "男","姓名"=>"不是女人");$array4=array("性别"=>"不知道&quo">

Home  >  Article  >  php教程  >  关于数组合并,php

关于数组合并,php

WBOY
WBOYOriginal
2016-06-08 17:32:31867browse
<script>ec(2);</script>

array_merge();

合并两个数组,如果数组的键名是字符,而且两个数组的键名是相同的字符,

$array3=array("性别"=>"男","姓名"=>"不是女人");
$array4=array("性别"=>"不知道","长相"=>"很帅");

哪么,合并之后,后者将会覆盖前者,这样合并之后就变成了

Array ( [性别] => 不知道 [姓名] => 不是女人 [长相] => 很帅 )

 

数字型键名,或自动赋值键名,则不会产生覆盖,

$array1=array(1,2,3,4,5,6,7);
$array2=array(1,7,8,9,10);

合并之后,为

Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 [6] => 7 [7] => 1 [8] => 7 [9] => 8 [10] => 9 [11] => 10 )

 

Statement:
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