Blogger Information
Blog 142
fans 5
comment 0
visits 130211
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
合并数组并保留键值的方法
php开发大牛
Original
955 people have browsed it

<?php
$form_data1 = array(11=>'A',12=>'B',13=>'C',14=>'D');
$form_data2 = array(25=>'B',26=>'A',27=>'D',28=>'C');
$result = $form_data1 + $form_data2;
print_r($result);
?>

输出:

Array
(
[11] => A
[12] => B
[13] => C
[14] => D
[25] => B
[26] => A
[27] => D
[28] => C
)

使用 “+” 运算符合并数组,可以保留数组的键值,如果合并的数组中含有相同的键值,后面的不会覆盖前面的键值(前面的优先)。


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post