PHP返回数组内的对象变量

时间:2012-04-25 17:28:03

标签: php arrays json multidimensional-array

我正在编写一个PHP脚本来处理一些JSON数据。以下是(删节)var_dump($data)。我想返回与["[question(13), option(0)]"]相关联的值,即20。我无法弄清楚如何做到这一点。我试过了$data->[question(13), option(0)]$data->question(13)。 (我试着查看一下,但我不确定符号的含义,所以我不确定我在寻找什么)

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"
}

2 个答案:

答案 0 :(得分:3)

使用扩展对象访问表示法:

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

或者只是要求正常数组并将其用作普通数组。

json_decode($json, true);

答案 1 :(得分:1)

试试这个

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