Home > 类库下载 > PHP类库 > The difference between array_merge and array+array in php

The difference between array_merge and array+array in php

高洛峰
Release: 2016-10-14 10:58:20
Original
1790 people have browsed it

array_merge discards the original numeric key, retains the key in string form, and then forms a new array. No matter whether the key name

is the same, it will not be merged, unless the key name and value are the same at the same time and must be in string form. keys are merged. The thing about array+array is that no matter what your situation is, it will only put the data of the previous array into the newly generated array first, and then see if the second array is larger than the first array. If there are many, more will be added in. It only counts the number, but in this case it will be added in:


$a = array('d'=>'aass','e'=>'adsdfd', 'asd'=>'asdsdd','ddfg'=>'dssdf');
$b = array('d'=>'adddd','adsdfd','asdfsddddd','d'=>'aass' );
$d = $a + $b;

$e = array_merge($a,$b);

var_dump($d);
var_dump($e);Print: array 'd' => string'aass ' (length=4) 'e' => string'adsdfd'

(length=6) 'asd' => string'asdsdd' (length=6) 'ddfg' => string'dssdf' (length=5) 0

=> string'adsdfd' (length=6) 1 => string'asdfsddddd' (length=10)array 'd' => string'aass' (length=4) 'e' => string'adsdfd'

(length=6) 'asd' => string'asdsdd' (length=6) 'ddfg' => string'dssdf' (length=5) 0

=> string'adsdfd' (length=6) 1 => string'asdfsddddd' (length=10)

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template