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"
}
1
  • You should really have your properties follow common variable name conventions. Commented Apr 25, 2012 at 17:32

2 Answers 2

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);
Sign up to request clarification or add additional context in comments.

2 Comments

Ahhh... the infamous curly brackets. Thanks! Out of curiosity, what does that notation mean? Are those instance variables of an object?
@Emerson: Yes, they are. Check the stackoverflow.com/questions/3737139/… for more information.
1

try this

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.