我有一個數組:獲得子陣列關鍵的PHP
Array
(
[47] => Array
(
[name] => 3543 good
[price] => 100.0000
[image] => data/hp_1.jpg
[discount] =>
[stock_status] =>
[weight_class] => kg
)
[28] => Array
(
[name] => HTC Touch HD
[price] => 100.0000
[image] => data/htc_touch_hd_1.jpg
[discount] =>
[stock_status] =>
[weight_class] => g
)
[41] => Array
(
[name] => iMac
[price] => 100.0000
[image] => data/imac_1.jpg
[discount] =>
[stock_status] =>
[weight_class] => kg
)
[40] => Array
(
[name] => iPhone
[price] => 101.0000
[image] => data/iphone_1.jpg
[discount] =>
[stock_status] =>
[weight_class] => kg
)
)
我需要的子陣列鍵(47,28等),因爲它是我的產品ID
我跑foreach循環獲取詳細信息並分配給新陣列,例如'name' => $result['name']
,但無法弄清楚如何定位產品ID。在它
foreach($array as $product_id => $result)
echo $product_id . ' costs ' . $result['price'] . "\n";
[PHP foreach循環鍵值]的可能重複(https://stackoverflow.com/questions/1834703/php-foreach-loop-key-value) – mickmackusa