如何访问数组中的特定对象值


How to acces specific object value in array?

我正在开发dropbox API,这样我就可以从路径构建图像库,但我有点陷入了这个数组中。我想从这个数组中访问图像的路径值。同时将其显示为dropbox图像库。请帮帮我。我有点困了!非常感谢。

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
    )
)

假设您调用此数组$imagesArray,以获得图像的路径,它将使用foreach循环:

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

假设你的结果在$data变量中,那么你可以得到所有的图像路径:

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

现在,$imagePaths变量中有了所有图像路径。