如何从php中的数组对象获取数据

时间:2016-06-15 02:32:57

标签: php arrays object multidimensional-array

使用var_export函数

后,我有这样的数据
Google_Service_Drive_FileList::__set_state(array(
    'collection_key' => 'items',
    'internal_gapi_mappings' => array() ,
    'etag' => NULL,
    'itemsType' => 'Google_Service_Drive_DriveFile',
    'itemsDataType' => 'array',
    'kind' => NULL,
    'nextLink' => NULL,
    'nextPageToken' => NULL,
    'selfLink' => NULL,
    'modelData' => array(
        'items' => array(
            0 => array(
                'id' => '1dOiZFO6nFEYKSLnMRS9mKZPXFBjztg_BwgEmNOPC2tQ',
                'title' => 'Php zend download',
                 )
) ,
    ) ,
    'processed' => array() ,
))

我怎样才能从中获取数据。 我正在尝试将其存储在变量$response

print_r($response->modelData['items']['0']['id']);

但一无所获。

2 个答案:

答案 0 :(得分:0)

我尝试过很多东西但是没有用。 但是现在我删除了var_export 并使用$response['modelData']['items']['0']['id'];其中$response是一个对象类型,它工作并给了我id的值。

仅打印print_r($response)时我得到:

Google_Service_Drive_FileListObject([collection_key:
    protected ] => items[internal_gapi_mappings:
        protected ] => Array() [etag] => [itemsType:
            protected ] => Google_Service_Drive_DriveFile[itemsDataType:
                protected ] => array [kind] => [nextLink] => [nextPageToken] => [selfLink] => [modelData:
                    protected ] => Array(
                        [items] => Array(
                            [0] => Array(
                                [id] => 0BzwXST - A2MuCY0FOd3ZNUVJQYk0[webContentLink] => https: //docs.google.com/uc?id=0BzwXST-A2MuCY0FOd3ZNUVJQYk0&export=download [title] => aucti.pdf )
                                ) ,
                            ) ,
                            'processed' => array() ,
                        ))

但是我得到了var_export:

Google_Service_Drive_FileList::__set_state(array(
    'collection_key' => 'items',
    'internal_gapi_mappings' => array() ,
    'etag' => NULL,
    'itemsType' => 'Google_Service_Drive_DriveFile',
    'itemsDataType' => 'array',
    'kind' => NULL,
    'nextLink' => NULL,
    'nextPageToken' => NULL,
    'selfLink' => NULL,
    'modelData' => array(
        'items' => array(
            0 => array(
                'id' => '0BzwXST-A2MuCY0FOd3ZNUVJQYk0',
                'webContentLink' => 'https://docs.google.com/uc?id=0BzwXST-A2MuCY0FOd3ZNUVJQYk0&export=download',
                'title' => 'aucti.pdf',
            ) ,
        ) ,
    ) ,
    'processed' => array() ,
))

答案 1 :(得分:0)

只需将其选为

即可
include "connection.php";