键值对中括号时来自PHP数组的回显值

时间:2014-04-23 00:19:51

标签: php arrays

快速提问,当数组中的键包含带括号的名称等时,如何回显变量。请参阅下面的数组:

 [data] => Array
    (
        [0] => stdClass Object
            (
                [id] => 4
                [contact_id] => 
                [status] => Complete
                [is_test_data] => 0
                [datesubmitted] => 2014-04-16 22:18:39
                [sResponseComment] => 
                [responseID] => 4
                [[question(1), option(0)]] => 
                [[question(2)]] => John
                [[question(3)]] => Wtf@wtf.com
                [[question(5)]] => 0975735289
                [[question(6)]] => 3010
                [[question(9), option(0)]] => 
                [[question(10)]] => Testing
                [[question(11)]] => Later
                [[question(12)]] => This year


            )

让我们说我想回答问题2的答案,即“约翰”。我该怎么做呢?

1 个答案:

答案 0 :(得分:1)

你有一个包含对象数组的数组:

echo $array['data'][0]->{'[question(2)]'};