2016-03-29 95 views
1

我正在使用Dropbox API,所以我可以從路徑構建圖像庫,但我有點卡在這個數組中。我想從這個數組訪問圖像的路徑值。同時顯示爲dropbox圖像gallary。請幫幫我。我有點卡住了!謝謝。如何訪問數組中的特定對象值?

Array 
(
    [code] => 200 
    [body] => Array 
    (
     [0] => stdClass Object 
     (
      [rev] => 246830441 
      [thumb_exists] => 1 
      [photo_info] => stdClass Object 
      (
       [lat_long] => 
       [time_taken] => 
       [image_dimensions] => Array 
        (
         [0] => 1128 
         [1] => 2407 
        ) 

      ) 
      [path] => /DSC_0528.JPG 
      [is_dir] => 
      [client_mtime] => Tue, 29 Mar 2016 17:39:12 +0000 
      [icon] => page_white_picture 
      [read_only] => 
      [modifier] => 
      [bytes] => 1042035 
      [modified] => Tue, 29 Mar 2016 17:39:12 +0000 
      [size] => 1 MB 
      [root] => dropbox 
      [mime_type] => image/jpeg 
      [revision] => 2 
     ) 

     [1] => stdClass Object 
     (
      [rev] => 346830441 
      [thumb_exists] => 1 
      [photo_info] => stdClass Object 
       (
        [lat_long] => 
        [time_taken] => Sun, 30 Sep 2012 00:54:59 +0000 
        [image_dimensions] => Array 
         (
          [0] => 324 
          [1] => 503 
         ) 

       ) 
      [path] => /389881_320848687954970_100000895238850_994084_116636550_n.jpg 
      [is_dir] => 
      [client_mtime] => Tue, 29 Mar 2016 17:39:25 +0000 
      [icon] => page_white_picture 
      [read_only] => 
      [modifier] => 
      [bytes] => 134294 
      [modified] => Tue, 29 Mar 2016 17:39:25 +0000 
      [size] => 131.1 KB 
      [root] => dropbox 
      [mime_type] => image/jpeg 
      [revision] => 3 
     ) 
    ) 

    [headers] => Array 
    (
     [server] => nginx 
     [date] => Tue, 29 Mar 2016 18:58:05 GMT 
     [content-type] => text/javascript 
     [transfer-encoding] => chunked 
     [connection] => keep-alive 
     [x-content-type-options] => nosniff 
     [set-cookie] => gvc=MTc0MjQ4ODE2ODkwMTIxMzU1NzEyNTIxNjM3MTc3ODIwODUwMjY0; expires=Sun, 28 Mar 2021 18:58:05 GMT; httponly; Path=/; secure 
     [x-dropbox-request-id] => 62dd80f2be78340a6b8aaa62b1d66e16 
     [pragma] => no-cache 
     [cache-control] => no-cache 
     [x-dropbox-http-protocol] => None 
     [x-frame-options] => SAMEORIGIN 
     [x-server-response-time] => 126 
    ) 
) 

回答

2

比方說,你叫這個數組$imagesArray,讓這將是一個foreach循環圖片的路徑:

<?php 
    foreach($imagesArray['body'] as $image){ 
    echo "path is : ".$image->path; 
    } 
?> 
+0

謝謝先生:)。你知道如何從drop box api獲取完整路徑嗎? –

+0

不客氣!我不確定通過「完整路徑」瞭解您的意思? –

+0

我想通過這個路徑顯示圖像gallary,但我認爲這個路徑是不夠的圖像gallary。 –

1

假設你已經在$ data變量的結果比你可以得到所有圖像路徑爲:

$imagePaths = array_map(function($image) { 
    return $image->path; 
}, $data['body']); 

現在,您已經在$ imagePaths變量中顯示所有圖像路徑。

+0

謝謝先生:)。你知道如何從下拉框中獲取完整路徑嗎? –

+0

到目前爲止,我還沒有使用Dropbox API。但也可能有一個選項來獲取基本網址。將檢查並讓你知道。 –

+0

你需要你的幫助先生。 –