數(shù)組結(jié)構(gòu):array ( 'payee_id' => 2381, 'items' => array ( 300 => array ( 'item_id' => 300, ' price' => 50, ), 372 => array ( 'item_id' => 372, 'price' => 90, ), ),) 我正在嘗試使用動(dòng)態(tài)獲取item_id和price。代碼foreach($data as $key => $value) { Log::debug($value[300]['price']);}使用上面的代碼,我可以拿到鑰匙300 price,但我也需要拿到鑰匙372。
1 回答

UYOU
TA貢獻(xiàn)1878條經(jīng)驗(yàn) 獲得超4個(gè)贊
使用的另一種解決方案 foreach()
<?php
foreach($data as $key => $value) { // if `$data` equal to $data['items'] as you mentioned in your question `Log::debug($value[300]['price']);`
foreach ($value as $finalValue) { // loop for inner array
echo $finalValue['price']."<br/>"; // print price in new line
}
}
?>
- 1 回答
- 0 關(guān)注
- 168 瀏覽
添加回答
舉報(bào)
0/150
提交
取消