2017-03-06 38 views
1

我使用的是谷歌電子表格API,我嘗試在PHP中將對象轉換爲數組。無法將對象更改爲數組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 
      ) 

    ) 

) 
+0

你有什麼試過的? – hassan

回答

1

你應該這樣使用。

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

感謝您的接受 – vel

0

您可以嘗試使用類型轉換,像這樣的數組對象轉換爲數組:

$array = (array) $obj; 
+0

這不起作用 – user6016913

+0

你可以請你發佈你想轉換的對象嗎? – Freid001

+0

你已經發布了一個數組^上面。如果你想訪問說id元素,你可以這樣做:$ id = $ array ['Google \ Spreadsheet \ Worksheetxml'] ['id'] [0]; – Freid001