AndyGB Posted October 6, 2015 Share Posted October 6, 2015 Hi I am converting a JSON object into an array and displaying like so: $json = json_decode($json); print_r($json); The results of which are: stdClass Object ( [orders] => Array ( [0] => stdClass Object ( [id] => 1429118021 [email] => test@mailinator.com [closed_at] => [created_at] => 2015-10-06T18:31:45+01:00 [updated_at] => 2015-10-06T18:31:45+01:00 [number] => 2 [note] => [token] => 6c92c7c6a6fd812eb9dfc4c8b2e2517b [gateway] => Bank Deposit [test] => [total_price] => 39.94 [subtotal_price] => 31.94 [total_weight] => 357 [total_tax] => 5.32 [taxes_included] => 1 [currency] => GBP [financial_status] => pending [confirmed] => 1 [total_discounts] => 0.00 [total_line_items_price] => 31.94 [cart_token] => db1e1fc102f3a3ae565feebf5793bfdc [buyer_accepts_marketing] => [name] => #1002 [referring_site] => http://sebi024.myshopify.com/ [landing_site] => /collections/all [cancelled_at] => [cancel_reason] => [total_price_usd] => 60.52 [checkout_token] => 06a996b75a8cb03819096c93cd2a2d63 [reference] => What I am basically trying to do is get the values, such as the ID number, which I was hoping to do like this: $json['orders'][0]['id'] Clearly that was too easy :/ I am guessing I can't do that because these are objects within arrays within objects? Quote Link to comment Share on other sites More sharing options...
Barand Posted October 6, 2015 Share Posted October 6, 2015 use json_decode($json, true); to get an array as the result. Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted October 6, 2015 Share Posted October 6, 2015 (edited) Nevermind You need to set to the second argument to truewhen calling json_decode $json = json_decode($json, true); Edited October 6, 2015 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
AndyGB Posted October 6, 2015 Author Share Posted October 6, 2015 Ah, thanks for that Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.