PHP:從多維數組獲取單個值
<?php
print_r($details);
?>
喜的朋友我打印的內容的$細節在PHP代碼值和出把我在瀏覽器中得到如下。
Array (
[0] =>
Array ([item_id] => 8 [row] => [merchant_id] => 1 [discount] => [currentController] => store [price] => 60|Large [qty] => 1 [notes] => [cooking_ref] => Cooking reference 1
[ingredients] => Array ([0] => Ingredients 1) [require_addon_5] => 2
[sub_item] => Array (
[5] => Array ([0] => 2|10|Addon Item 1|right [1] => 3|20|Addon Item 2|right)
[6] => Array ([0] => 2|10|Addon Item 1|right [1] => 3|20|Addon Item 2|right)
[7] => Array ([0] => 2|10|Addon Item 1|right [1] => 3|20|Addon Item 2|right)
)
[addon_qty] => Array (
[5] => Array ([0] => 1 [1] => 1)
[6] => Array ([0] => 1 [1] => 1)
[7] => Array ([0] => 1 [1] => 1)
)
[require_addon_6] => 2
[require_addon_7] => 2
[two_flavors] =>
[non_taxable] => 2
[addon_ids] => Array ([0] => 2 [1] => 3 [2] => 2 [3] => 3 [4] => 2 [5] => 3)
)
)
現在我得到「ITEM_ID」,「cooking_ref」,分項目和addon_qty的值作爲單個陣列。現在我想知道我們如何訪問這些值。我已經提前嘗試過類似
<?php
print_r($details);
echo "item_id : ".$details[0]['item_id']" <br />"
echo "price : ".$details[0]['price']" <br />"
echo "cooking_ref : ".$details[0]['cooking_ref']" <br />"
echo "cooking_ref : ".$details[0]['cooking_ref']" <br />"
echo "ingredients : "" <br />";
foreach($details['sub_item'] as $sub_item)
{
print_r($sub_item);
echo "<br /><br />";
$sub_item_array_val +=1;
}
?>
但沒有workedout我可以在任何一個請建議我如何從上面的陣列存取權限這些值,由於
嘗試用'$ details [0] ['sub_item']替換$ details ['sub_item']' –