如何访问php数组中最里面的值

时间:2017-05-03 11:42:15

标签: php arrays json associative-array soql

我有这个数组作为json格式的输出。

Array
(
    [totalSize] => 1
    [done] => 1
    [records] => Array
        (
            [0] => Array
                (
                    [attributes] => Array
                        (
                            [type] => Emp
                            [url] => /services/data/v20.0/sobjects/AG
                        )

                    [Name] => John Doe
                    [Company__r] => Array
                        (
                            [attributes] => Array
                                (
                                    [type] => Comp
                                    [url] => /services/data/v20.0/AZ
                                )

                            [Name] => LINEA
                        )

                )

        )

)

我能够使用以下代码访问值为John Doe的Name属性。

    foreach ($result['records'] as $record) {
    print_r($record['Name']);
    print_r("<br>");
}

但我无法访问价值为&#34; Linea&#34;的Name属性。我该如何访问最里面的值。 ?

1 个答案:

答案 0 :(得分:0)

因为它在'Company__r'数组中,所以它应该是这样的。

foreach ($result['records'] as $record) {

   echo $record['Name']; //John Doe
   echo  $record['Company__r']['Name']; //LINEA


}