0

I have this array which as output from a json format.

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
                        )

                )

        )

)

I was able to access the Name property which the value is John Doe with the following code..

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

But i am unable to access the Name property which the value is "Linea". How should i access the innermost value. ?

1 Answers1

0

Because Its inside the 'Company__r' array so it should be get like this .

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

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


}
JYoThI
  • 11,977
  • 1
  • 11
  • 26