我試圖用一個標準的foreach循環例子來閱讀我的陣列,它不會增加...簡單陣列循環不工作
$array = json_decode('{"variants":[{"barcode":"610373772697","compare_at_price":null,"created_at":"2015-06-27T01:56:42-07:00","fulfillment_service":"manual","grams":190,"id":3856358467,"inventory_management":"shopify","inventory_policy":"deny","option1":"Default Title","option2":null,"option3":null,"position":1,"price":"20.99","product_id":1259972867,"requires_shipping":true,"sku":"1125442","taxable":true,"title":"Default Title","updated_at":"2015-06-27T01:56:42-07:00","inventory_quantity":100,"old_inventory_quantity":100,"image_id":null,"weight":0.42,"weight_unit":"lb"},{"barcode":"364031530906","compare_at_price":null,"created_at":"2015-06-27T01:56:42-07:00","fulfillment_service":"manual","grams":131,"id":3856359043,"inventory_management":"shopify","inventory_policy":"deny","option1":"Default Title","option2":null,"option3":null,"position":1,"price":"17.24","product_id":1259973059,"requires_shipping":true,"sku":"0116350","taxable":true,"title":"Default Title","updated_at":"2015-06-27T01:56:42-07:00","inventory_quantity":100,"old_inventory_quantity":100,"image_id":null,"weight":0.29,"weight_unit":"lb"},{"barcode":"364031534003","compare_at_price":null,"created_at":"2015-06-27T01:56:43-07:00","fulfillment_service":"manual","grams":390,"id":3856359107,"inventory_management":"shopify","inventory_policy":"deny","option1":"Default Title","option2":null,"option3":null,"position":1,"price":"27.74","product_id":1259973123,"requires_shipping":true,"sku":"0116368","taxable":true,"title":"Default Title","updated_at":"2015-06-27T01:56:43-07:00","inventory_quantity":100,"old_inventory_quantity":100,"image_id":null,"weight":0.86,"weight_unit":"lb"}]}', true);
foreach ($array as $key => $val) {
print "$key = $val\n";
}
將返回: 「變種=陣列」
我無法深入到數組的第二級並獲取sku和id值。
非常感謝! – Kailas
歡迎您參觀:http://stackoverflow.com/help/someone-answers –
@Dagon祝賀PHP金牌/徽章。 ;-) *去拿他們的Tigger!* –