我有这个数组
Array
(
[disc-art] => Array
(
[original] => upload/c/4/c4eea45ce0f5e8d5698f5ff2d18b4566.jpg
[preview] => Array
(
[dvd-disc] => upload/c/4/d_disc_c4eea45ce0f5e8d5698f5ff2d18b4566.jpg
)
)
[cover-art] => Array
(
[original] => upload/7/2/72bb5a03708c99c822a792c76c00e8d1.jpg
[preview] => Array
(
[dvd-cover] => upload/7/2/d_cover_72bb5a03708c99c822a792c76c00e8d1.jpg
[dvd-spine] => upload/7/2/d_spine_72bb5a03708c99c822a792c76c00e8d1.jpg
[dvd-back] => upload/7/2/d_back_72bb5a03708c99c822a792c76c00e8d1.jpg
)
)
[insert-art] => Array
(
[original] => upload/b/1/b1f8e49d77121c01011acaa90cabc8ee.jpg
[preview] => Array
(
[dvd-insert] => upload/b/1/d_insert_b1f8e49d77121c01011acaa90cabc8ee.jpg
)
)
[boxshot] => Array
(
[preview] => Array
(
[boxshot] => upload/7/2/d_boxshot_72bb5a03708c99c822a792c76c00e8d1.jpg
)
)
)
我想返回一个访问每个preview
的数组并获取内容
array('dvd-disc' => '...path...', 'dvd-cover' => '...path...', etc...)
请帮助,这是漫长的一天,我想回家! :)
修改
更正 - 我希望我的最终数组看起来像这样......
array(
'dvd-disc' => '<img src="'.$path.'" alt="'.$type.'" />',
'dvd-cover' => '<img src="'.$path.'" alt="'.$type.'" />',
etc...
);
其中$path
是每个preview's
子值的值,$ type是每个preview's
子键的值
答案 0 :(得分:3)
$new_array = array();
foreach($main_array as $sub_array)
{
if(isset($sub_array['preview']))
{
foreach($sub_array['preview'] as $type => $image_url)
{
$new_array[$type] = '<img src="'.$image_url.'" alt="'.$type.'" />';
}
}
}
答案 1 :(得分:2)
// (the array you are bring in is $mainArray)
// New array we'll be creating
$previewPaths = array()
foreach ($mainArray as $item) {
foreach ($item['preview'] as $previewName => $previewPath) {
$previewPaths[$previewName] = '<img src="'.$previewPath.'" alt="'.$previewName.'" />',;
}
}