我有一个数组。我想让每个photosArray都是唯一项。例如:在我的Facebook中,如果我发布了一张图片,那么photosArray有一个项目,但如果我在一个帖子中发布了多张图片,那么photosArray有多个项目。
现在我想打印所有的照片。
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
)
)
)
我正在尝试这个代码,但它不工作
foreach($specified_post_photo_array AS $item)
{
foreach($item['photosArray'] AS $pitem)
{
$photo=$pitem['url'];
}
}
But Its show no result
你应该把你的代码改成:
foreach($specified_post_photo_array[0] AS $item)
{
foreach($item['photosArray'] AS $pitem)
{
$photo=$pitem['url'];
}
}
试试这个代码…
$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'];
}
希望这有帮助…!!