时间:2021-07-01 10:21:17 帮助过:4人阅读
PHP 的 array_merge 会将 数值 变成 0, 1, 2..., 就算是强制转换成字串也一样.
$a1 = array(
??? '9' => '0',
??? '311' => '1',
??? '快乐' => '2',
??? '2009a' => '3');
$a2 = array(
??? '2009' => '11',
??? '圣诞节' => '22',
??? '111a' => '33');
$amerge = array();
$amerge = array_merge($a1, $a2);
print_r($amerge);
?>
输出结果
Array
(
??? [0] => 0
??? [1] => 1
??? [快乐] => 2
??? [2009a] => 3
??? [2] => 11
??? [圣诞节] => 22
??? [111a] => 33
)
于 官方网站查(array_merge ), 使用 "+" 就可以 merge, 而且会将 key(hash、index) 值保留.
$a1 = array(
??? '9'???? => '0',
??? '311'?? => '1',
??? '快乐'?? => '2',
??? '2009a' => '3'
);
$a2 = array(
??? '2009'? => '11',
??? '圣诞节' => '22',
??? '111a'? => '33'
);
$amerge = array();
$amerge = $a1 + $a2;
print_r($amerge);
?>
输出结果
Array原文网站 / 转载自: Tsung Hao
(
??? [9] => 0
??? [311] => 1
??? [快乐] => 2
??? [2009a] => 3
??? [2009] => 11
??? [圣诞节] => 22
??? [111a] => 33
)
This work, unless otherwise expressly stated, is licensed under a
Creative Commons Attribution-ShareAlike 3.0 Unported License
.