无法将对象更改为数组 php

Can't change object into array php

我正在使用 google 电子表格 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
            )

    )

)

您可以尝试使用数组类型转换将对象转换为数组,如下所示:

$array = (array) $obj;

您可以使用 PHP Google Spreadsheet Client library.

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

你应该这样使用。

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