我知道這可能已被問過很多次。但在我的情況下,我用這個獲取嵌套數組中元素的值
echo $result["tracks"]["title"];
Fatal error: Cannot use object of type stdClass as array in C:\wamp\www\withheader.php on line 26
,並通過使用print_r ($result);
我得到以下結果
我想陣列軌道和元素標題的結果得到這個錯誤。因此理想情況下,輸出應該是可變具有值DHL (Deprecated)
stdClass Object ([increment_id] => 100000045 [store_id] => 1 [created_at] => 2015-09-07 07:34:06 [updated_at] => 2015-09-18 06:02:02 [shipping_address_id] => 441 [order_id] => 224 [total_qty] => 2.0000 [shipment_id] => 48 [items] => Array ([0] => stdClass Object ([parent_id] => 48 [sku] => testsimpleadmin [name] => testsimpleadmin [order_item_id] => 642 [product_id] => 57050 [weight] => 2.0000 [price] => 100.0000 [qty] => 1.0000 [item_id] => 96) [1] => stdClass Object ([parent_id] => 48 [sku] => 12121221 [name] => women fancy bag [order_item_id] => 643 [product_id] => 57090 [weight] => 1.0000 [price] => 71.0000 [qty] => 1.0000 [item_id] => 97)) [tracks] => Array ([0] => stdClass Object ([parent_id] => 48 [created_at] => 2015-09-18 06:02:02 [updated_at] => 2015-09-18 06:02:02 [carrier_code] => dhl [title] => DHL (Deprecated) [number] => 456 [order_id] => 224 [track_id] => 5)) [comments] => Array ())
這是一個對象不是一個數組。 –
'echo $ result-> tracks [0] - > title' –
感謝宇智波,正是我一直在尋找的。 您可以添加這個答案! –