我想弄清楚如何通過這個stdClass對象循環。我正在嘗試獲取路徑的每個內容數組項[0] - [?]的值。PHP的stdClass對象數組循環
對象數組是這樣的:
stdClass Object
(
[hash] => zzzzzzzzzzzzzzzzzzzzzzzzzzzz
[revision] => 22
[rev] => 161f5f4043
[thumb_exists] =>
[bytes] => 0
[modified] => Sun, 23 Mar 2014 18:05:38 +0000
[path] => /Camera Uploads
[is_dir] => 1
[icon] => folder_photos
[root] => dropbox
[contents] => Array
(
[0] => stdClass Object
(
[revision] => 47
[rev] => 2f1f5f4043
[thumb_exists] => 1
[bytes] => 3212196
[modified] => Sun, 23 Mar 2014 18:07:05 +0000
[client_mtime] => Wed, 05 Feb 2014 19:10:14 +0000
[path] => /Camera Uploads/2014-02-05 14.10.13.jpg
[is_dir] =>
[icon] => page_white_picture
[root] => dropbox
[mime_type] => image/jpeg
[size] => 3.1 MB
)
[1] => stdClass Object
(
etc etc...
目前我想下面的代碼迴路:
line 75: print_r ($dropbox->GetMetadata($file->path));
line 77: foreach ($dropbox->GetMetadata($file->path) as $arr) {
line 78: foreach ($arr as $obj) {
line 79: $path = $obj->path;
line 80: echo $path;
line 81: }
line 82: }
,但我不斷收到此錯誤:
(!) Warning: Invalid argument supplied for foreach() in
C:\wamp\www\test\sample.php on line 78
Call Stack
# Time Memory Function Location
1 0.0011 157592 {main}() ..\sample.php:0
只要刪除內部的foreach循環'var_dump($ arr);'你就會看到。順便說一句,'$ arr'是一個誤導性的變量名稱。當你迭代對象的屬性時,它應該是'$ property' – hek2mgl
@ hek2mgl然後我得到一個錯誤**注意:試圖獲取C:\ wamp \ www \ test \ sample.php中非對象的屬性第78行** – StealthRT
再想一想,再試一次,你會看到。一旦你開悟了,你會發現沒有什麼可說的 – hek2mgl