PHP如何访问多维数组

时间:2017-05-23 09:52:46

标签: php arrays multidimensional-array

我知道有多种多维数组访问解决方案。但他们中的任何一个都不适合我。

我有这个数组,我需要通过遍历整个数组来访问name属性。如何访问Name属性中的Value'TEXTPRINT'?

Array
(
    [0] => Array
        (
            [ParentSurvey] => Array
                (
                    [attributes] => Array
                        (
                            [type] => SM_Survey__c
                            [url] => /services/data/v36.0/sobjects/SM_Survey__c/a181400000FHVy0AAH
                        )

                    [Id] => a181400000FHVy0AAH
                    [Company__c] => a0Qa000000ME65MEAT
                    [Type__c] => Company Critical Roles
                    [Company__r] => Array
                        (
                            [attributes] => Array
                                (
                                    [type] => Company__c
                                    [url] => /services/data/v36.0/sobjects/Company__c/a0Qa000000ME65MEAT
                                )

                            [Id] => a0Qa000000ME65MEAT
                            [Name] => TEXTPRINT
                        )

                )

            [DescList] => Array
                (
                    [0] => Array
                        (
                            [attributes] => Array
                                (
                                    [type] => SM_Survey_Detail__c
                                    [url] => /services/data/v36.0/sobjects/SM_Survey_Detail__c/a171400000PkHmsAAF
                                )

                            [Id] => a171400000PkHmsAAF
                            [CR_Designation__c] => a0ka0000004r6biAAA
                            [SM_Survey__c] => a181400000FHVy0AAH
                            [CR_Designation__r] => Array
                                (
                                    [attributes] => Array
                                        (
                                            [type] => Designation__c
                                            [url] => /services/data/v36.0/sobjects/Designation__c/a0ka0000004r6biAAA
                                        )

                                    [Id] => a0ka0000004r6biAAA
                                    [Name] =>Manager
                                )

                        )

我尝试使用此代码打印值..

foreach ($result as $record){
    print_r($record['Array']['ParentSurvey']['Company__r']['Name']);
}

1 个答案:

答案 0 :(得分:1)

试试这个

foreach ($result as $record){
    print_r($record['ParentSurvey']['Company__r']['Name']);
}