0

I'm writing a PHP script to work with some JSON data. Below is an (abridged) var_dump($data). I want to return the value associated with ["[question(13), option(0)]"] which is 20. I can't figure out how to do it. I've tried $data->[question(13), option(0)] and $data->question(13). (I tried to look this up but I'm not sure what the notation means, so I'm not sure what I'm looking for)

object(stdClass)#133 (36) {
  ["id"]=>
  string(1) "1"
  ["contact_id"]=>
  string(0) ""
  ["status"]=>
  string(8) "Complete"
  ["is_test_data"]=>
  string(1) "0"
  ["datesubmitted"]=>
  string(19) "2012-04-19 17:11:00"
  ["[question(5)]"]=>
  string(11) "C.    40%, 40%"
  ["[question(9)]"]=>
  string(47) "D.    EBITDA and Free cash flow are the same thing"
  ["[question(10)]"]=>
  string(48) "A.    Accounts Payable as % of sales would increase"
  ["[question(11)]"]=>
  string(20) "E.    None of the above"
  ["[question(12)]"]=>
  string(97) "A.     A larger portion of initial investment is equity which can increase exit return potential."
  ["[question(13), option(0)]"]=>
  string(2) "20"
  ["[url("embed")]"]=>
  string(0) ""
  ["[variable("STANDARD_IP")]"]=>
  string(13) "38.107.74.230"
  ["[variable("STANDARD_LONG")]"]=>
  string(10) "-73.976303"
  ["[variable("STANDARD_LAT")]"]=>
  string(9) "40.761902"
}
emersonthis
  • 32,822
  • 59
  • 210
  • 375

2 Answers2

3

Either use extended object access notation:

$data->{'[question(13), option(0)]'}

Or just ask for normal array and use it as normal array.

json_decode($json, true);
Konrad Borowski
  • 11,584
  • 3
  • 57
  • 71
  • Ahhh... the infamous curly brackets. Thanks! Out of curiosity, what does that notation mean? Are those instance variables of an object? – emersonthis Apr 25 '12 at 17:58
  • @Emerson: Yes, they are. Check the http://stackoverflow.com/questions/3737139/reference-what-does-this-symbol-mean-in-php for more information. – Konrad Borowski Apr 25 '12 at 18:00
1

try this

echo $data->{'[question(13), option(0)]'};
miro
  • 735
  • 8
  • 16