Reputation: 45
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
Upvotes: 0
Views: 97
Reputation: 130
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..!!
Upvotes: 0
Reputation: 111829
You should change your code into:
foreach($specified_post_photo_array[0] AS $item)
{
foreach($item['photosArray'] AS $pitem)
{
$photo=$pitem['url'];
}
}
Upvotes: 6