Note the usage of the phparray_merge function. Notes for using phparray_merge functions this article mainly introduces a problem that needs to be paid attention to when using phparray_merge functions. This article describes a problem that should be paid attention to when combining arrays with array_merge functions.
This article mainly introduces a problem that needs to be paid attention to when using the php array_merge function. This article describes the problem that array_merge does not merge the number key names when merging arrays. you need to pay attention when using this function. For more information, see
When using the array_merge function in php, the same key name will be overwritten, but please refer to the following code:
The code is as follows:
$ A1 = array (1 => 'ABC', 3 => 10 );
$ A2 = array (1 => 'efg', 3 => 20 );
Print_r (array_merge ($ a1, $ a2 ));
What will be output? We expected:
The code is as follows:
Array
(
[1] => efg
[3] => 20
)
Actually, the output is:
The code is as follows:
Array
(
[0] => abc
[1] => 10
[2] => efg
[3] => 20
)
Not only is it not overwritten, but the number key is re-indexed continuously.
At first thought this was a bug, and then turned over the php manual http://php.net/manual/zh/function.array-merge.php
「 If the input array contains the same string key name, the value after the key name overwrites the previous one. However, if the array contains a number key name, the subsequent values will not overwrite the original values, but will be appended to the back.
If only one array is assigned and the array is indexed by number, the key name is re-indexed continuously .」
Http://www.bkjia.com/PHPjc/976534.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/976534.htmlTechArticlephp array_merge functions need to pay attention to the use of a problem this article mainly introduces the use of php array_merge functions need to pay attention to a problem, this article explains the array_merge array merge will not combine...