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"
}
asked Apr 25, 2012 at 17:28
emersonthis
33.6k62 gold badges224 silver badges386 bronze badges
-
You should really have your properties follow common variable name conventions.Jason McCreary– Jason McCreary2012年04月25日 17:32:22 +00:00Commented Apr 25, 2012 at 17:32
2 Answers 2
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);
answered Apr 25, 2012 at 17:30
null
12k3 gold badges60 silver badges74 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
emersonthis
Ahhh... the infamous curly brackets. Thanks! Out of curiosity, what does that notation mean? Are those instance variables of an object?
null
@Emerson: Yes, they are. Check the stackoverflow.com/questions/3737139/… for more information.
try this
echo $data->{'[question(13), option(0)]'};
Comments
Explore related questions
See similar questions with these tags.
lang-php