当前位置:网站首页>Array in PHP_ The pit of merge
Array in PHP_ The pit of merge
2022-07-24 15:48:00 【aben_ sky】
PHP The official document is right array_merge The definition of
array_merge( array $array1[, array $...] ) : array
array_merge() Combine the cells of one or more arrays , The values in an array are appended to the back of the previous array . Returns an array as a result .
If the input array has the same string key name , Then the value after the key name will overwrite the previous value . However , If the array contains a numeric key name , The latter value will not overwrite the original value , It's attached to the back .
If only one array is given and the array is digitally indexed , The key name is re indexed in a continuous manner .
Description of pit
Look at the bold part of the document above , If you believe , And just believe what the document says , Then you're wrong .
See the example given in the document :
$array1 = array();
$array2 = array(1 => "data");
$result = array_merge($array1, $array2);
var_dump($result);
The result is :
Array
(
[0] => data
)
Um. , Yes , There is no problem with the example given in the document , There's really no problem .
however , If both arrays are not empty , And there are numerical subscripts , It will also re index the numerical subscript
$arr = [
11 => 'a',
12 => 'b'
];
$arr2 = [
'a' => 'a1',
14 => 'b1'
];
var_dump(array_merge($arr, $arr2));
The result is :
array(4) {
[0]=>
string(1) "a"
[1]=>
string(1) "b"
["a"]=>
string(2) "a1"
[2]=>
string(2) "b1"
}
The numerical subscripts have been reset !
so, In this case, only + To deal with it :
$result = $arr + $arr2;
边栏推荐
- Configuring WAPI certificate security policy for Huawei wireless devices
- Hard core innovation that database needs to care about in the future
- SQL row to column, column to row
- [quantitative test]
- Error: pidfile (celerybeat.pid) already exists when celery starts beat
- Dynamics crm: sharing records for users and teams
- How to deal with being attacked? Advanced anti DDoS IP protection strategy
- With this machine learning drawing artifact, papers and blogs can get twice the result with half the effort!
- Using JS to implement click events
- 遭受DDoS时,高防IP和高防CDN的选择
猜你喜欢

Withdrawal of IPO application, Yunzhou intelligent "tour" of unmanned boat enterprise fails to enter the science and Technology Innovation Board

Error: pidfile (celerybeat.pid) already exists when celery starts beat

ReentrantLock 可重入锁

Kubectl_ Easy to use command line tool: Oh my Zsh_ Tips and tricks

Error 1053: the service did not respond to the start or control request in a timely fashion

yolov3 训练自己的数据集
![[SWT] scrolling container to realize commodity list style](/img/84/07e7c794aaef3fb64f173b50150b21.png)
[SWT] scrolling container to realize commodity list style

Read the paper with me - multi model text recognition network

自适应设计和响应式设计

AttributeError: module ‘seaborn‘ has no attribute ‘histplot‘
随机推荐
Citic securities account opening process, is it safe to open an account on your mobile phone
Dynamics crm: sharing records for users and teams
Automatic derivation of pytorch
iptables常用命令小清单
Arduino IDE ESP32固件安装和升级教程
你不能只会flex居中布局,精制动画讲解所有flex布局方式!通俗易懂纯干货教程!...
3、 Set foundation ArrayList set and simple student management system
Netease email (126/163): authorization code acquisition strategy
R language Visual facet chart, multivariable grouping nested multilevel t-test, and specify reference level, visual multivariable grouping nested multilevel faceting boxplot, and add significance leve
2.19 haas506 2.0开发教程 - bluetooth - 蓝牙通信(仅支持2.2以上版本)
Fine tune layoutlm V3 for bill data processing and content recognition
SQL row to column, column to row
【SWT】滚动容器实现商品列表样式
每天20分钟之feign
Do you understand the working principle of gyroscope?
MySQL source code analysis -- data structure of index
Varnish4.0缓存代理配置
请问好的券商的排名?网上开户安全吗
IP protocol - network segment division
2022/7/18 CF training