PHP合并数组,键值不变
PHP中有合并数组的函数 array_merge(),但是这个函数有一个缺点,就是在使用的时候,会使数组为数字的键值重置,丢失原来的键值;
后来,找了个小的方法,解决了个问题;
$a = array("111"=>"a","112"=>"b"); $b = array("113"=>"c","114"=>"d"); $c = array(); foreach( $a as $key => $value ) { $c[$key] = $value; } foreach( $b as $key => $value ) { $c[$key] = $value; } //这样新的数组就保留了原来的数组的键值其实用"+"操作符也可以实现类似的功能!
相关推荐
songshijiazuaa 2020-09-01
zyyjay 2020-11-09
xuebingnan 2020-11-05
samtrue 2020-11-22
stefan0 2020-11-22
yifangs 2020-10-13
songshijiazuaa 2020-09-24
hebiwtc 2020-09-18
天步 2020-09-17
83911535 2020-11-13
whatsyourname 2020-11-13
zhouyuqi 2020-11-10
Noneyes 2020-11-10
mathchao 2020-10-28
王志龙 2020-10-28
wwwsurfphpseocom 2020-10-28
diskingchuan 2020-10-23