Search code examples
phparraysdropbox

How to iterate the Dropbox result array in PHP


How to iterate an array object in php.My Requirement is to save the path of the below array which is coming from Dropbox. Can someone help me in this please. The below is the result when i print "var_dump($data)" which is given by the Dropbox while trying to get the files of a particular folder. The Object looks like :

    array (size=14)
  'read_only' => boolean false
  'hash' => string '6bb3719bc8b46aaa392d5787df8e71d7' (length=32)
  'revision' => int 11
  'bytes' => int 0
  'thumb_exists' => boolean false
  'rev' => string 'b403db773' (length=9)
  'modified' => string 'Thu, 26 Nov 2015 20:54:51 +0000' (length=31)
  'size' => string '0 bytes' (length=7)
  'path' => string '/1' (length=2)
  'is_dir' => boolean true
  'modifier' => null
  'root' => string 'dropbox' (length=7)
  'contents' => 
    array (size=28)
      0 => 
        array (size=14)
          'rev' => string '13403db773' (length=10)
          'thumb_exists' => boolean true
          'path' => string '/1/flower-171644_640 (1).jpg' (length=28)
          'is_dir' => boolean false
          'client_mtime' => string 'Fri, 27 Nov 2015 07:56:44 +0000' (length=31)
          'icon' => string 'page_white_picture' (length=18)
          'read_only' => boolean false
          'modifier' => null
          'bytes' => int 50552
          'modified' => string 'Fri, 27 Nov 2015 07:56:44 +0000' (length=31)
          'size' => string '49.4 KB' (length=7)
          'root' => string 'dropbox' (length=7)
          'mime_type' => string 'image/jpeg' (length=10)
          'revision' => int 19
      1 => 
        array (size=14)
          'rev' => string '14403db773' (length=10)
          'thumb_exists' => boolean true
          'path' => string '/1/flower-171644_640 (2).jpg' (length=28)
          'is_dir' => boolean false
          'client_mtime' => string 'Fri, 27 Nov 2015 08:00:18 +0000' (length=31)
          'icon' => string 'page_white_picture' (length=18)
          'read_only' => boolean false
          'modifier' => null
          'bytes' => int 50552
          'modified' => string 'Fri, 27 Nov 2015 08:00:18 +0000' (length=31)
          'size' => string '49.4 KB' (length=7)
          'root' => string 'dropbox' (length=7)
          'mime_type' => string 'image/jpeg' (length=10)
          'revision' => int 20
      2 => 
        array (size=14)
          'rev' => string '15403db773' (length=10)
          'thumb_exists' => boolean true
          'path' => string '/1/flower-171644_640 (3).jpg' (length=28)
          'is_dir' => boolean false
          'client_mtime' => string 'Fri, 27 Nov 2015 08:01:08 +0000' (length=31)
          'icon' => string 'page_white_picture' (length=18)
          'read_only' => boolean false
          'modifier' => null
          'bytes' => int 50552
          'modified' => string 'Fri, 27 Nov 2015 08:01:08 +0000' (length=31)
          'size' => string '49.4 KB' (length=7)
          'root' => string 'dropbox' (length=7)
          'mime_type' => string 'image/jpeg' (length=10)
          'revision' => int 21
      3 => 
        array (size=14)
          'rev' => string '16403db773' (length=10)
          'thumb_exists' => boolean true
          'path' => string '/1/flower-171644_640 (4).jpg' (length=28)
          'is_dir' => boolean false
          'client_mtime' => string 'Fri, 27 Nov 2015 08:24:20 +0000' (length=31)
          'icon' => string 'page_white_picture' (length=18)
          'read_only' => boolean false
          'modifier' => null
          'bytes' => int 50552
          'modified' => string 'Fri, 27 Nov 2015 08:24:20 +0000' (length=31)
          'size' => string '49.4 KB' (length=7)
          'root' => string 'dropbox' (length=7)
          'mime_type' => string 'image/jpeg' (length=10)
          'revision' => int 22
      4 => 
        array (size=14)
          'rev' => string '17403db773' (length=10)
          'thumb_exists' => boolean true
          'path' => string '/1/flower-171644_640 (5).jpg' (length=28)
          'is_dir' => boolean false
          'client_mtime' => string 'Fri, 27 Nov 2015 08:25:31 +0000' (length=31)
          'icon' => string 'page_white_picture' (length=18)
          'read_only' => boolean false
          'modifier' => null
          'bytes' => int 50552
          'modified' => string 'Fri, 27 Nov 2015 08:25:31 +0000' (length=31)
          'size' => string '49.4 KB' (length=7)
          'root' => string 'dropbox' (length=7)
          'mime_type' => string 'image/jpeg' (length=10)
          'revision' => int 23
      5 => 
        array (size=14)
          'rev' => string '19403db773' (length=10)
          'thumb_exists' => boolean true
          'path' => string '/1/flower-171644_640 (6).jpg' (length=28)
          'is_dir' => boolean false
          'client_mtime' => string 'Fri, 27 Nov 2015 08:30:47 +0000' (length=31)
          'icon' => string 'page_white_picture' (length=18)
          'read_only' => boolean false
          'modifier' => null
          'bytes' => int 50552
          'modified' => string 'Fri, 27 Nov 2015 08:30:47 +0000' (length=31)
          'size' => string '49.4 KB' (length=7)
          'root' => string 'dropbox' (length=7)
          'mime_type' => string 'image/jpeg' (length=10)
          'revision' => int 25
      6 => 
        array (size=14)
          'rev' => string '1a403db773' (length=10)
          'thumb_exists' => boolean true
          'path' => string '/1/flower-171644_640 (7).jpg' (length=28)
          'is_dir' => boolean false
          'client_mtime' => string 'Fri, 27 Nov 2015 08:31:34 +0000' (length=31)
          'icon' => string 'page_white_picture' (length=18)
          'read_only' => boolean false
          'modifier' => null
          'bytes' => int 50552
          'modified' => string 'Fri, 27 Nov 2015 08:31:34 +0000' (length=31)
          'size' => string '49.4 KB' (length=7)
          'root' => string 'dropbox' (length=7)
          'mime_type' => string 'image/jpeg' (length=10)
          'revision' => int 26
      7 => 
        array (size=14)
          'rev' => string '1b403db773' (length=10)
          'thumb_exists' => boolean true
          'path' => string '/1/flower-171644_640 (8).jpg' (length=28)
          'is_dir' => boolean false
          'client_mtime' => string 'Fri, 27 Nov 2015 08:33:09 +0000' (length=31)
          'icon' => string 'page_white_picture' (length=18)
          'read_only' => boolean false
          'modifier' => null
          'bytes' => int 50552
          'modified' => string 'Fri, 27 Nov 2015 08:33:09 +0000' (length=31)
          'size' => string '49.4 KB' (length=7)
          'root' => string 'dropbox' (length=7)
          'mime_type' => string 'image/jpeg' (length=10)
          'revision' => int 27
      8 => 
        array (size=14)
          'rev' => string '1c403db773' (length=10)
          'thumb_exists' => boolean true
          'path' => string '/1/flower-171644_640 (9).jpg' (length=28)
          'is_dir' => boolean false
          'client_mtime' => string 'Fri, 27 Nov 2015 08:33:35 +0000' (length=31)
          'icon' => string 'page_white_picture' (length=18)
          'read_only' => boolean false
          'modifier' => null
          'bytes' => int 50552
          'modified' => string 'Fri, 27 Nov 2015 08:33:35 +0000' (length=31)
          'size' => string '49.4 KB' (length=7)
          'root' => string 'dropbox' (length=7)
          'mime_type' => string 'image/jpeg' (length=10)
          'revision' => int 28
      9 => 
        array (size=14)
          'rev' => string '1d403db773' (length=10)
          'thumb_exists' => boolean true
          'path' => string '/1/flower-171644_640 (10).jpg' (length=29)
          'is_dir' => boolean false
          'client_mtime' => string 'Fri, 27 Nov 2015 08:34:40 +0000' (length=31)
          'icon' => string 'page_white_picture' (length=18)
          'read_only' => boolean false
          'modifier' => null
          'bytes' => int 50552
          'modified' => string 'Fri, 27 Nov 2015 08:34:40 +0000' (length=31)
          'size' => string '49.4 KB' (length=7)
          'root' => string 'dropbox' (length=7)
          'mime_type' => string 'image/jpeg' (length=10)
          'revision' => int 29
      10 => 
        array (size=14)
          'rev' => string '1e403db773' (length=10)
          'thumb_exists' => boolean true
          'path' => string '/1/flower-171644_640 (11).jpg' (length=29)
          'is_dir' => boolean false
          'client_mtime' => string 'Fri, 27 Nov 2015 08:35:09 +0000' (length=31)
          'icon' => string 'page_white_picture' (length=18)
          'read_only' => boolean false
          'modifier' => null
          'bytes' => int 50552
          'modified' => string 'Fri, 27 Nov 2015 08:35:09 +0000' (length=31)
          'size' => string '49.4 KB' (length=7)
          'root' => string 'dropbox' (length=7)
          'mime_type' => string 'image/jpeg' (length=10)
          'revision' => int 30
      11 => 
        array (size=14)
          'rev' => string '1f403db773' (length=10)
          'thumb_exists' => boolean true
          'path' => string '/1/flower-171644_640 (12).jpg' (length=29)
          'is_dir' => boolean false
          'client_mtime' => string 'Fri, 27 Nov 2015 08:36:01 +0000' (length=31)
          'icon' => string 'page_white_picture' (length=18)
          'read_only' => boolean false
          'modifier' => null
          'bytes' => int 50552
          'modified' => string 'Fri, 27 Nov 2015 08:36:00 +0000' (length=31)
          'size' => string '49.4 KB' (length=7)
          'root' => string 'dropbox' (length=7)
          'mime_type' => string 'image/jpeg' (length=10)
          'revision' => int 31
      12 => 
        array (size=14)
          'rev' => string '20403db773' (length=10)
          'thumb_exists' => boolean true
          'path' => string '/1/flower-171644_640 (13).jpg' (length=29)
          'is_dir' => boolean false
          'client_mtime' => string 'Fri, 27 Nov 2015 08:38:11 +0000' (length=31)
          'icon' => string 'page_white_picture' (length=18)
          'read_only' => boolean false
          'modifier' => null
          'bytes' => int 50552
          'modified' => string 'Fri, 27 Nov 2015 08:38:09 +0000' (length=31)
          'size' => string '49.4 KB' (length=7)
          'root' => string 'dropbox' (length=7)
          'mime_type' => string 'image/jpeg' (length=10)
          'revision' => int 32
      13 => 
        array (size=14)
          'rev' => string '21403db773' (length=10)
          'thumb_exists' => boolean true
          'path' => string '/1/flower-171644_640 (14).jpg' (length=29)
          'is_dir' => boolean false
          'client_mtime' => string 'Fri, 27 Nov 2015 08:39:14 +0000' (length=31)
          'icon' => string 'page_white_picture' (length=18)
          'read_only' => boolean false
          'modifier' => null
          'bytes' => int 50552
          'modified' => string 'Fri, 27 Nov 2015 08:39:13 +0000' (length=31)
          'size' => string '49.4 KB' (length=7)
          'root' => string 'dropbox' (length=7)
          'mime_type' => string 'image/jpeg' (length=10)
          'revision' => int 33
      14 => 
        array (size=14)
          'rev' => string '22403db773' (length=10)
          'thumb_exists' => boolean true
          'path' => string '/1/flower-171644_640 (15).jpg' (length=29)
          'is_dir' => boolean false
          'client_mtime' => string 'Fri, 27 Nov 2015 08:40:14 +0000' (length=31)
          'icon' => string 'page_white_picture' (length=18)
          'read_only' => boolean false
          'modifier' => null
          'bytes' => int 50552
          'modified' => string 'Fri, 27 Nov 2015 08:40:14 +0000' (length=31)
          'size' => string '49.4 KB' (length=7)
          'root' => string 'dropbox' (length=7)
          'mime_type' => string 'image/jpeg' (length=10)
          'revision' => int 34
      15 => 
        array (size=14)
          'rev' => string '23403db773' (length=10)
          'thumb_exists' => boolean true
          'path' => string '/1/flower-171644_640 (16).jpg' (length=29)
          'is_dir' => boolean false
          'client_mtime' => string 'Fri, 27 Nov 2015 08:40:31 +0000' (length=31)
          'icon' => string 'page_white_picture' (length=18)
          'read_only' => boolean false
          'modifier' => null
          'bytes' => int 50552
          'modified' => string 'Fri, 27 Nov 2015 08:40:30 +0000' (length=31)
          'size' => string '49.4 KB' (length=7)
          'root' => string 'dropbox' (length=7)
          'mime_type' => string 'image/jpeg' (length=10)
          'revision' => int 35
      16 => 
        array (size=14)
          'rev' => string '24403db773' (length=10)
          'thumb_exists' => boolean true
          'path' => string '/1/flower-171644_640 (17).jpg' (length=29)
          'is_dir' => boolean false
          'client_mtime' => string 'Fri, 27 Nov 2015 08:44:02 +0000' (length=31)
          'icon' => string 'page_white_picture' (length=18)
          'read_only' => boolean false
          'modifier' => null
          'bytes' => int 50552
          'modified' => string 'Fri, 27 Nov 2015 08:44:02 +0000' (length=31)
          'size' => string '49.4 KB' (length=7)
          'root' => string 'dropbox' (length=7)
          'mime_type' => string 'image/jpeg' (length=10)
          'revision' => int 36
      17 => 
        array (size=14)
          'rev' => string '25403db773' (length=10)
          'thumb_exists' => boolean true
          'path' => string '/1/flower-171644_640 (18).jpg' (length=29)
          'is_dir' => boolean false
          'client_mtime' => string 'Fri, 27 Nov 2015 08:46:37 +0000' (length=31)
          'icon' => string 'page_white_picture' (length=18)
          'read_only' => boolean false
          'modifier' => null
          'bytes' => int 50552
          'modified' => string 'Fri, 27 Nov 2015 08:46:37 +0000' (length=31)
          'size' => string '49.4 KB' (length=7)
          'root' => string 'dropbox' (length=7)
          'mime_type' => string 'image/jpeg' (length=10)
          'revision' => int 37
      18 => 
        array (size=14)
          'rev' => string '26403db773' (length=10)
          'thumb_exists' => boolean true
          'path' => string '/1/flower-171644_640 (19).jpg' (length=29)
          'is_dir' => boolean false
          'client_mtime' => string 'Fri, 27 Nov 2015 08:47:16 +0000' (length=31)
          'icon' => string 'page_white_picture' (length=18)
          'read_only' => boolean false
          'modifier' => null
          'bytes' => int 50552
          'modified' => string 'Fri, 27 Nov 2015 08:47:15 +0000' (length=31)
          'size' => string '49.4 KB' (length=7)
          'root' => string 'dropbox' (length=7)
          'mime_type' => string 'image/jpeg' (length=10)
          'revision' => int 38
      19 => 
        array (size=14)
          'rev' => string '27403db773' (length=10)
          'thumb_exists' => boolean true
          'path' => string '/1/flower-171644_640 (20).jpg' (length=29)
          'is_dir' => boolean false
          'client_mtime' => string 'Fri, 27 Nov 2015 08:48:08 +0000' (length=31)
          'icon' => string 'page_white_picture' (length=18)
          'read_only' => boolean false
          'modifier' => null
          'bytes' => int 50552
          'modified' => string 'Fri, 27 Nov 2015 08:48:08 +0000' (length=31)
          'size' => string '49.4 KB' (length=7)
          'root' => string 'dropbox' (length=7)
          'mime_type' => string 'image/jpeg' (length=10)
          'revision' => int 39
      20 => 
        array (size=14)
          'rev' => string '28403db773' (length=10)
          'thumb_exists' => boolean true
          'path' => string '/1/flower-171644_640 (21).jpg' (length=29)
          'is_dir' => boolean false
          'client_mtime' => string 'Fri, 27 Nov 2015 08:53:21 +0000' (length=31)
          'icon' => string 'page_white_picture' (length=18)
          'read_only' => boolean false
          'modifier' => null
          'bytes' => int 50552
          'modified' => string 'Fri, 27 Nov 2015 08:53:21 +0000' (length=31)
          'size' => string '49.4 KB' (length=7)
          'root' => string 'dropbox' (length=7)
          'mime_type' => string 'image/jpeg' (length=10)
          'revision' => int 40
      21 => 
        array (size=14)
          'rev' => string '29403db773' (length=10)
          'thumb_exists' => boolean true
          'path' => string '/1/flower-171644_640 (22).jpg' (length=29)
          'is_dir' => boolean false
          'client_mtime' => string 'Fri, 27 Nov 2015 08:54:11 +0000' (length=31)
          'icon' => string 'page_white_picture' (length=18)
          'read_only' => boolean false
          'modifier' => null
          'bytes' => int 50552
          'modified' => string 'Fri, 27 Nov 2015 08:54:11 +0000' (length=31)
          'size' => string '49.4 KB' (length=7)
          'root' => string 'dropbox' (length=7)
          'mime_type' => string 'image/jpeg' (length=10)
          'revision' => int 41
      22 => 
        array (size=14)
          'rev' => string '2a403db773' (length=10)
          'thumb_exists' => boolean true
          'path' => string '/1/flower-171644_640 (23).jpg' (length=29)
          'is_dir' => boolean false
          'client_mtime' => string 'Fri, 27 Nov 2015 08:54:41 +0000' (length=31)
          'icon' => string 'page_white_picture' (length=18)
          'read_only' => boolean false
          'modifier' => null
          'bytes' => int 50552
          'modified' => string 'Fri, 27 Nov 2015 08:54:41 +0000' (length=31)
          'size' => string '49.4 KB' (length=7)
          'root' => string 'dropbox' (length=7)
          'mime_type' => string 'image/jpeg' (length=10)
          'revision' => int 42
      23 => 
        array (size=14)
          'rev' => string '12403db773' (length=10)
          'thumb_exists' => boolean true
          'path' => string '/1/flower-171644_640.jpg' (length=24)
          'is_dir' => boolean false
          'client_mtime' => string 'Fri, 27 Nov 2015 05:21:13 +0000' (length=31)
          'icon' => string 'page_white_picture' (length=18)
          'read_only' => boolean false
          'modifier' => null
          'bytes' => int 50552
          'modified' => string 'Fri, 27 Nov 2015 05:21:12 +0000' (length=31)
          'size' => string '49.4 KB' (length=7)
          'root' => string 'dropbox' (length=7)
          'mime_type' => string 'image/jpeg' (length=10)
          'revision' => int 18
      24 => 
        array (size=14)
          'rev' => string '11403db773' (length=10)
          'thumb_exists' => boolean true
          'path' => string '/1/frog-927764_640 (1).jpg' (length=26)
          'is_dir' => boolean false
          'client_mtime' => string 'Fri, 27 Nov 2015 05:14:07 +0000' (length=31)
          'icon' => string 'page_white_picture' (length=18)
          'read_only' => boolean false
          'modifier' => null
          'bytes' => int 54351
          'modified' => string 'Fri, 27 Nov 2015 05:14:07 +0000' (length=31)
          'size' => string '53.1 KB' (length=7)
          'root' => string 'dropbox' (length=7)
          'mime_type' => string 'image/jpeg' (length=10)
          'revision' => int 17
      25 => 
        array (size=14)
          'rev' => string '18403db773' (length=10)
          'thumb_exists' => boolean true
          'path' => string '/1/frog-927764_640 (2).jpg' (length=26)
          'is_dir' => boolean false
          'client_mtime' => string 'Fri, 27 Nov 2015 08:27:21 +0000' (length=31)
          'icon' => string 'page_white_picture' (length=18)
          'read_only' => boolean false
          'modifier' => null
          'bytes' => int 54351
          'modified' => string 'Fri, 27 Nov 2015 08:27:21 +0000' (length=31)
          'size' => string '53.1 KB' (length=7)
          'root' => string 'dropbox' (length=7)
          'mime_type' => string 'image/jpeg' (length=10)
          'revision' => int 24
      26 => 
        array (size=14)
          'rev' => string '10403db773' (length=10)
          'thumb_exists' => boolean true
          'path' => string '/1/frog-927764_640.jpg' (length=22)
          'is_dir' => boolean false
          'client_mtime' => string 'Fri, 27 Nov 2015 04:52:42 +0000' (length=31)
          'icon' => string 'page_white_picture' (length=18)
          'read_only' => boolean false
          'modifier' => null
          'bytes' => int 54351
          'modified' => string 'Fri, 27 Nov 2015 04:52:42 +0000' (length=31)
          'size' => string '53.1 KB' (length=7)
          'root' => string 'dropbox' (length=7)
          'mime_type' => string 'image/jpeg' (length=10)
          'revision' => int 16
      27 => 
        array (size=14)
          'rev' => string 'd403db773' (length=9)
          'thumb_exists' => boolean true
          'path' => string '/1/lotos.jpg' (length=12)
          'is_dir' => boolean false
          'client_mtime' => string 'Fri, 27 Nov 2015 03:09:12 +0000' (length=31)
          'icon' => string 'page_white_picture' (length=18)
          'read_only' => boolean false
          'modifier' => null
          'bytes' => int 63500
          'modified' => string 'Fri, 27 Nov 2015 03:09:12 +0000' (length=31)
          'size' => string '62 KB' (length=5)
          'root' => string 'dropbox' (length=7)
          'mime_type' => string 'image/jpeg' (length=10)
          'revision' => int 13
  'icon' => string 'folder' (length=6)

Solution

  • You can do something like this:

    $paths = array();
    
    // $dropbox_array is the multidimensional array you're getting from dropbox
    
    foreach($dropbox_array['contents'] as $file_desp_array){
        $paths[] = $file_desp_array['path'];
    }
    
    var_dump($paths);