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

时间:2016-03-29 19:05:28

标签: php dropbox

我正在使用Dropbox API,所以我可以从路径构建图库,但我有点卡在这个数组中。我想从这个数组访问图像的路径值。同时将其显示为dropbox image 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 个答案:

答案 0 :(得分:2)

假设您调用此数组if shoppingList.count > 3 { shoppingList.removeAtIndex(3) } ,以获取foreach循环的图像路径:

$imagesArray

答案 1 :(得分:1)

假设您在$ data变量中的结果超过了所有图像路径:

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

现在您在$ imagePaths变量中拥有所有图像路径。