二维数组合并
array(7) {
$a = array( array("id" => "201307", "value" => 535), array("id" => "201306", "value" => 5), array("id" => "201305", "value" => 758), array("id" => "201304", "value" => 10), array("id" => "201303", "value" => 582), array("id" => "201302", "value" => 390), array("id" => "201301", "value" => 473),);$b = array( array("id" => "201307", "values" => 3588), array("id" => "201306", "values" => 3177), array("id" => "201305", "values" => 2946), array("id" => "201304", "values" => 2419), array("id" => "201303", "values" => 2287), array("id" => "201302", "values" => 2251), array("id" => "201301", "values" => 2474),);$c = array_map('array_merge', $a, $b);print_r($c);
$a = array( array("id" => "201307", "value" => 535), array("id" => "201306", "value" => 5), array("id" => "201305", "value" => 758), array("id" => "201304", "value" => 10), array("id" => "201303", "value" => 582), array("id" => "201302", "value" => 390), array("id" => "201301", "value" => 473),);$b = array( array("id" => "201307", "values" => 3588), array("id" => "201306", "values" => 3177), array("id" => "201305", "values" => 2946), array("id" => "201304", "values" => 2419), array("id" => "201303", "values" => 2287), array("id" => "201302", "values" => 2251), array("id" => "201301", "values" => 2474),);$c = array_map('array_merge', $a, $b);print_r($c);
array(7) {
[0]=> array(2) { ["id"]=> string(6) "201307" ["value"]=> int(535) }
[1]=> array(2) { ["id"]=> string(6) "201305" ["value"]=> int(758) }
[2]=> array(2) { ["id"]=> string(6) "201304" ["value"]=> int(10) }
[3]=> array(2) { ["id"]=> string(6) "201303" ["value"]=> int(582) }
[4]=> array(2) { ["id"]=> string(6) "201302" ["value"]=> int(390) }
[5]=> array(2) { ["id"]=> string(6) "201301" ["value"]=> int(473) } }
array(7) {
[0]=> array(2) { ["id"]=> string(6) "201307" ["values"]=> int(3588) }
[1]=> array(2) { ["id"]=> string(6) "201306" ["values"]=> int(3177) }
[2]=> array(2) { ["id"]=> string(6) "201305" ["values"]=> int(2946) }
[3]=> array(2) { ["id"]=> string(6) "201304" ["values"]=> int(2419) }
[4]=> array(2) { ["id"]=> string(6) "201303" ["values"]=> int(2287) }
[5]=> array(2) { ["id"]=> string(6) "201302" ["values"]=> int(2251) }
[6]=> array(2) { ["id"]=> string(6) "201301" ["values"]=> int(2474) } }
版主 要是条数不对应呢 想得到下面的记录怎么办!
最后想得到
array(7) {
[0]=> array(2) { ["id"]=> string(6) "201307" ["value"]=> int(535) ["values"]=> int(3588) }
[1]=> array(2) { ["id"]=> string(6) "201306" ["values"]=> int(3177) }
[2]=> array(2) { ["id"]=> string(6) "201305" ["value"]=> int(758)["values"]=> int(2946) }
[3]=> array(2) { ["id"]=> string(6) "201304" ["value"]=> int(10) ["values"]=> int(2419) }
[4]=> array(2) { ["id"]=> string(6) "201303" ["value"]=> int(582) ["values"]=> int(2287) }
[5]=> array(2) { ["id"]=> string(6) "201302" ["value"]=> int(390) ["values"]=> int(2251) }
[6]=> array(2) { ["id"]=> string(6) "201301" ["value"]=> int(473) ["values"]=> int(2474) } }
那你就用循环呗
能帮着写个例子么。版主。我写一上午了。 新手不会啊!