大家好,我想从数组2维度创建新的1数组维度,代码如下:
[0] => Array(
[photo_data_id] => 0
[photo_image] => Array
(
[0] => 37a.jpg
)
[photo_status] => 1
)
[1] => Array(
[photo_data_id] => 1
[photo_image] => Array
(
[0] => 6.jpg
[1] => 6a.jpg
[2] => 20141001_073231.jpg
)
[photo_status] => 1
)
[2] => Array(
[photo_data_id] => 2
[photo_image] => Array
(
[0] => 20.jpg
[1] => 21.jpg
[2] => 22.jpg
[3] => 23.jpg
[4] => 24.png
)
[photo_status] => 1
)
和我想要的结果如下,而不是存储到数据库中:
[0] => Array(
[photo_data_id] => 0
[photo_image] => 37a.jpg
[photo_status] => 1
)
[1] => Array(
[photo_data_id] => 1
[photo_image] => 6.jpg
[photo_status] => 1
)
[2] => Array(
[photo_data_id] => 1
[photo_image] => 6a.jpg
[photo_status] => 1
)
[3] => Array(
[photo_data_id] => 1
[photo_image] => 20141001_073231.jpg
[photo_status] => 1
)
[4] => Array(
[photo_data_id] => 2
[photo_image] => 20.jpg
[photo_status] => 1
)
[5] => Array(
[photo_data_id] => 2
[photo_image] => 21.jpg
[photo_status] => 1
)
[6] => Array(
[photo_data_id] => 2
[photo_image] => 22.jpg
[photo_status] => 1
)
[7] => Array(
[photo_data_id] => 2
[photo_image] => 23.jpg
[photo_status] => 1
)
[8] => Array(
[photo_data_id] => 2
[photo_image] => 24.jpg
[photo_status] => 1
)
请帮助我,我是新手,谢谢之前:)
答案 0 :(得分:1)
$result = array();
foreach ($array1 as $item) {
foreach ($item['photo_image'] as $image) {
$result[] = array(
'photo_data_id' => $item['photo_data_id'],
'photo_image' => $image,
'photo_status' => $item['photo_status'],
);
}
}
print_r($result);