0

I have an array. i want to get every photosArray as a unique item.such as example: in my Facebook i post a image if i post single image then photosArray have one item but if i post multiple image in a post then photosArray have multiple item.

now i want to print all post photo how.

Array
(
    [0] => Array
        (
            [0] => Array
                (
                    [photosArray] => Array
                        (
                            [0] => Array
                                (
                                    [__type] => File
                                    [name] => e24da5a6-e5a1-4d91-a8c7-64d046759382-file
                                    [url] => http://files.parse.com/c2dcf728-e2a3-4b2d-a8c8-6ec9b3c6502a/e24da5a6-e5a1-4d91-a8c7-64d046759382-file
                                )

                            [1] => Array
                                (
                                    [__type] => File
                                    [name] => e4029a4a-e928-4afd-8cf1-3a9084e40126-file
                                    [url] => http://files.parse.com/c2dcf728-e2a3-4b2d-a8c8-6ec9b3c6502a/e4029a4a-e928-4afd-8cf1-3a9084e40126-file
                                )

                            [2] => Array
                                (
                                    [__type] => File
                                    [name] => 5b7e30c7-7283-4115-b177-08e5652f80b1-file
                                    [url] => http://files.parse.com/c2dcf728-e2a3-4b2d-a8c8-6ec9b3c6502a/5b7e30c7-7283-4115-b177-08e5652f80b1-file
                                )

                        )


                    [createdAt] => 2014-04-20T13:49:00.012Z
                    [updatedAt] => 2014-04-20T13:49:00.012Z
                    [postid] => 12

                )

            [1] => Array
                (
                    [photosArray] => Array
                        (
                            [0] => Array
                                (
                                    [__type] => File
                                    [name] => d77c7975-bf50-4a2c-ad9e-975d2cd4c47b-file
                                    [url] => http://files.parse.com/c2dcf728-e2a3-4b2d-a8c8-6ec9b3c6502a/d77c7975-bf50-4a2c-ad9e-975d2cd4c47b-file
                                )

                            [1] => Array
                                (
                                    [__type] => File
                                    [name] => 730110b0-980b-4e40-be07-81509cb91efa-file
                                    [url] => http://files.parse.com/c2dcf728-e2a3-4b2d-a8c8-6ec9b3c6502a/730110b0-980b-4e40-be07-81509cb91efa-file
                                )

                            [2] => Array
                                (
                                    [__type] => File
                                    [name] => 9f246b77-cdf5-409c-8a99-5a0188dbcca9-file
                                    [url] => http://files.parse.com/c2dcf728-e2a3-4b2d-a8c8-6ec9b3c6502a/9f246b77-cdf5-409c-8a99-5a0188dbcca9-file
                                )

                        )


                    [createdAt] => 2014-04-20T13:57:08.231Z
                    [updatedAt] => 2014-04-20T13:57:08.231Z
                    [postid] => 112

                )

            [2] => Array
                (
                    [photosArray] => Array
                        (
                            [0] => Array
                                (
                                    [__type] => File
                                    [name] => 2c85f3be-69d8-4ca1-be51-8848bb73eb78-file
                                    [url] => http://files.parse.com/c2dcf728-e2a3-4b2d-a8c8-6ec9b3c6502a/2c85f3be-69d8-4ca1-be51-8848bb73eb78-file
                                )

                        )


                    [createdAt] => 2014-04-21T07:45:52.829Z
                    [updatedAt] => 2014-04-21T07:45:52.829Z
                    [postid] => 172

                )





            [3] => Array
                (
                    [photosArray] => Array
                        (
                            [0] => Array
                                (
                                    [__type] => File
                                    [name] => 6fd7458f-0ade-4bc6-9567-04c6bc197ea3-file
                                    [url] => http://files.parse.com/c2dcf728-e2a3-4b2d-a8c8-6ec9b3c6502a/6fd7458f-0ade-4bc6-9567-04c6bc197ea3-file
                                )

                        )

                    [createdAt] => 2014-04-21T07:45:52.829Z
                    [updatedAt] => 2014-04-21T07:45:52.829Z

                )

        )

)

I am trying this code but its not work

foreach($specified_post_photo_array AS $item)
{


    foreach($item['photosArray'] AS $pitem)
    {
        $photo=$pitem['url'];



    }

}

But Its show no result

5
  • Enable error reporting first. Commented May 13, 2014 at 6:05
  • no error show @AmalMurali Commented May 13, 2014 at 6:06
  • You're only traversing through the second level of your multi-demensional array. You need to go one level deeper to access $item['photosArray'] Commented May 13, 2014 at 6:06
  • Logic: FOREACH(ARRAY AS A){ FOREACH(A AS A_1) { FOREACH(A_1 AS ITEM) { echo ITEM; } } } Commented May 13, 2014 at 6:07
  • Or as Marcins' answer suggests! Commented May 13, 2014 at 6:08

2 Answers 2

6

You should change your code into:

foreach($specified_post_photo_array[0] AS $item)
{


    foreach($item['photosArray'] AS $pitem)
    {
        $photo=$pitem['url'];



    }

}
Sign up to request clarification or add additional context in comments.

1 Comment

if i want to separate as single item which [photosArray] have multiple item then what can i do @Marcin
0

Try this code..

$specified_post_photo_array = $specified_post_photo_array[0];

foreach($specified_post_photo_array as $key => $value)
{
   echo '<br> Photo 1 : '. $value['photosArray'][0]['url'];
   echo '<br> Photo 2 : '. $value['photosArray'][1]['url'];
   echo '<br> Photo 3 : '. $value['photosArray'][2]['url']; 
}

Hope this helps..!!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.