无法将对象更改为数组php

时间:2017-03-06 14:02:18

标签: php google-spreadsheet-api

我正在使用谷歌电子表格API,我尝试在PHP中将对象转换为数组。

请告诉我如何访问对象或数组键,值对。任何人都可以帮助我。

提前致谢。

Array
(
[Google\Spreadsheet\Worksheetxml] => Array
    (
        [id] => Array
            (
                [0] => https://spreadsheets.google.com/feeds/worksheets/1l5g5HbOuaDVCXb1Z3mMk7UesdJ5OOsUtGEekqDXRd-s/private/full/od6
            )

        [updated] => Array
            (
                [0] => 2017-03-01T14:18:45.232Z
            )

        [category] => Array
            (
                [@attributes] => Array
                    (
                        [scheme] => http://schemas.google.com/spreadsheets/2006
                        [term] => http://schemas.google.com/spreadsheets/2006#worksheet
                    )

            )

        [title] => Array
            (
                [0] => Sheet1
            )

        [content] => Array
            (
                [0] => Sheet1
            )

        [link] => Array
            (
                [0] => SimpleXMLElement Object
                    (
                        [@attributes] => Array
                            (
                                [rel] => http://schemas.google.com/spreadsheets/2006#listfeed
                                [type] => application/atom+xml
                                [href] => https://spreadsheets.google.com/feeds/list/1l5g5HbOuaDVCXb1Z3mMk7UesdJ5OOsUtGEekqDXRd-s/od6/private/full
                            )

                    )

                [1] => SimpleXMLElement Object
                    (
                        [@attributes] => Array
                            (
                                [rel] => http://schemas.google.com/spreadsheets/2006#cellsfeed
                                [type] => application/atom+xml
                                [href] => https://spreadsheets.google.com/feeds/cells/1l5g5HbOuaDVCXb1Z3mMk7UesdJ5OOsUtGEekqDXRd-s/od6/private/full
                            )

                    )

                [2] => SimpleXMLElement Object
                    (
                        [@attributes] => Array
                            (
                                [rel] => http://schemas.google.com/visualization/2008#visualizationApi
                                [type] => application/atom+xml
                                [href] => https://docs.google.com/spreadsheets/d/1l5g5HbOuaDVCXb1Z3mMk7UesdJ5OOsUtGEekqDXRd-s/gviz/tq?gid=0
                            )

                    )

                [3] => SimpleXMLElement Object
                    (
                        [@attributes] => Array
                            (
                                [rel] => http://schemas.google.com/spreadsheets/2006#exportcsv
                                [type] => text/csv
                                [href] => https://docs.google.com/spreadsheets/d/1l5g5HbOuaDVCXb1Z3mMk7UesdJ5OOsUtGEekqDXRd-s/export?gid=0&format=csv
                            )

                    )

                [4] => SimpleXMLElement Object
                    (
                        [@attributes] => Array
                            (
                                [rel] => self
                                [type] => application/atom+xml
                                [href] => https://spreadsheets.google.com/feeds/worksheets/1l5g5HbOuaDVCXb1Z3mMk7UesdJ5OOsUtGEekqDXRd-s/private/full/od6
                            )

                    )

                [5] => SimpleXMLElement Object
                    (
                        [@attributes] => Array
                            (
                                [rel] => edit
                                [type] => application/atom+xml
                                [href] => https://spreadsheets.google.com/feeds/worksheets/1l5g5HbOuaDVCXb1Z3mMk7UesdJ5OOsUtGEekqDXRd-s/private/full/od6/-u3c64m
                            )

                    )

            )

    )

[Google\Spreadsheet\WorksheetpostUrl] => Array
    (
        [0] => Array
            (
                [0] => https://spreadsheets.google.com/feeds/worksheets/1l5g5HbOuaDVCXb1Z3mMk7UesdJ5OOsUtGEekqDXRd-s/private/full
            )

    )

)

3 个答案:

答案 0 :(得分:1)

你应该这样使用。

foreach($yourArray as $key=>$value){
   $Updatedate  =  $value['updated'][0];
   $UpdateId  =  $value['id'][0];
}

答案 1 :(得分:0)

您可以尝试使用数组类型转换将对象转换为数组:

$array = (array) $obj;

答案 2 :(得分:0)

您可以使用PHP Google Spreadsheet Client library

您还需要使用Google APIs Client Library for PHP通过OAuth2进行身份验证。开发人员文档链接在github页面上。