如何合并这三个数组
$name ={"Tom", "John", "David"};
$v1 = {"Tom":100, "David":200};
$v2 = {"John":500, "Tom":400};
以两种不同的方式进入一个多维关联数组?一种方法是键顺序应该与数组“名称”的键顺序相同。
$name_merged_original_order = array (
"Tom" => Array(
"v1" => 100,
"v2" => 400
),
"John" => Array(
"v1" => "N/A",
"v2" => 500
),
"David" => Array(
"v1" => 100,
"v2" => "N/A"
)
)
另一种方法是数组“名称”的字母顺序:
$name_merged_asc = array (
"David" => Array(
"v1" => 100,
"v2" => "N/A"
),
"John" => Array(
"v1" => "N/A",
"v2" => 200
),
"Tom" => Array(
"v1" => 100,
"v2" => 400
),
)
棘手的部分是数组“v1”和“v2”没有作为“name”的键排序。他们也没有“名称”中的所有键。谢谢!