ホームページ >バックエンド開発 >PHPチュートリアル >複数の 2 次元配列を 1 つの配列に統合する方法
二维数组合并
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);Array
$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]=> 配列(2) { ["id"]=> string(6) "201307" ["値"]=> int(535) }
[1]=> 配列(2) { ["id"]=> string(6) "201305" ["値"]=> int(758) }
[2]=> 配列(2) { ["id"]=> string(6) "201304" ["値"]=> int(10) }
[3]=> 配列(2) { ["id"]=> string(6) "201303" ["値"]=> int(582) }
[4]=> 配列(2) { ["id"]=> string(6) "201302" ["値"]=> int(390) }
[5]=> 配列(2) { ["id"]=> string(6) "201301" ["値"]=> int(473) } }
array(7) {
[0]=> 配列(2) { ["id"]=> string(6) "201307" ["値"]=> int(3588) }
[1]=> 配列(2) { ["id"]=> string(6) "201306" ["値"]=> int(3177) }
[2]=> 配列(2) { ["id"]=> string(6) "201305" ["値"]=> int(2946) }
[3]=> 配列(2) { ["id"]=> string(6) "201304" ["値"]=> int(2419) }
[4]=> 配列(2) { ["id"]=> string(6) "201303" ["値"]=> int(2287) }
[5]=> 配列(2) { ["id"]=> string(6) "201302" ["値"]=> int(2251) }
[6]=> 配列(2) { ["id"]=> string(6) "201301" ["値"]=> int(2474) } }
バージョン主 要是条数不对应呢 次の面の记录怎么办! 配列(2) { ["id"]=> 文字列(6) "201307" ["値"]=> int(535) ["値"]=> int(3588) }
[1]=> 配列(2) { ["id"]=> string(6) "201306" ["値"]=> int(3177) }
[2]=> 配列(2) { ["id"]=> 文字列(6) "201305" ["値"]=> int(758)["値"]=> int(2946) }
[3]=> 配列(2) { ["id"]=> 文字列(6) "201304" ["値"]=> int(10) ["値"]=> int(2419) }
[4]=> 配列(2) { ["id"]=> string(6) "201303" ["値"]=> int(582) ["値"]=> int(2287) }
[5]=> 配列(2) { ["id"]=> string(6) "201302" ["値"]=> int(390) ["値"]=> int(2251) }
[6]=> 配列(2) { ["id"]=> string(6) "201301" ["値"]=> int(473) ["値"]=> int(2474) } }
那你就用循環呗
能帮着写例子么。版主。我写一上了。 新しい手不会啊!