0
我正在嘗試向這兩個數組中的每一個添加鍵,以便我可以將所有數據作爲一個數組訪問。這是我的。嘗試多個職位堆棧溢出,但到目前爲止一切都沒有澆築這個概念對我來說:PHP數組關聯數組
$result = array();
$age_men = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
$age_women = array("Sally"=>"32", "Debra"=>"30", "Miranda"=>"40");
$result += ["Men" => $age_men];
$result += ["Women" => $age_women];
print_r($result);
//desired output
Array
(
[Men] => Array
(
[Peter] => 35
[Ben] => 37
[Joe] => 43
)
[Women] => Array
(
[Sally] => 32
[Debra] => 30
[Miranda] => 40
)
)
$結果[「Men」] = $ age_men; $ result [「Women」] = $ age_women; – JYoThI
問題是什麼?你的代碼正是你想要的:https://3v4l.org/5U4Ok – Rizier123
你的代碼也在工作,那麼問題是什麼? – JYoThI