有沒有從另一個數組讀取數組的方法?如何在PHP中讀取另一個數組中的數組值?
這是我的2陣列,
$productArr = [
"PT" => [
"cat" => [ "image" => "cat.jpg", "desc" => "blah blah"],
"fish"=> [ "image" => "fish.jpg", "desc" => "blah blah"],
"dog" => [ "image" => "dog.jpg","desc" => "blah blah"],
],
"KC" => [
"Ice" => [ "image" => "ice.jpg", "desc" => "mah mah mah"],
"cold"=> [ "image" => "cold.jpg", "desc" => "mah mah mah"],
"water"=> [ "image" => "water.jpg", "desc" => "mah mah mah"],
],
];
$featuredArr = [
"KC" => "Ice",
"PT" => "cat",
];
例如,來自$featuredArr
「冰」 將與$productArr
「冰」 的鏈接,以產生 「DESC」 和 「圖像」。
只是使用該值作爲鍵,它們存在於另一方面,只要添加一個isset或數組鍵存在如果你想檢查一下,檢查下面的答案 – Ghost