我有以下数组,其中包含每个文件的信息。但它是单个数组。我想转换成一个数组,单个索引的数组包含单个图像的数组
array
(
'name' => array
(
'0' => '262702_221069867927769_100000742738048_692998_2241181_n.jpg'
'1' => '423541_261124687295172_100001929282529_556902_941592773_n.jpg'
)
'type' => array
(
'0' => 'image/jpeg'
'1' => 'image/jpeg'
)
'tmp_name' => array
(
'0' => 'C:\\wamp\\tmp\\phpB0.tmp'
'1' => 'C:\\wamp\\tmp\\phpB1.tmp'
)
'error' => array
(
'0' => 0
'1' => 0
)
'size' => array
(
'0' => 66699
'1' => 12013
)
)
我正在寻找的是将其转换为格式
array{
'0'=>array{
'name'=>'262702_221069867927769_100000742738048_692998_2241181_n.jpg',
'type'=>'image/jpeg',
.....
...
...}
'1'=>'0'=>array{
'name'=>'262702_221069867927769_100000742738048_692998_2241181_n.jpg',
'type'=>'image/jpeg',
.....
...
...}
}
我无法弥补任何人帮助我的好算法吗?
答案 0 :(得分:3)
$new_array = array();
foreach ($array as $attr => $img_data)
{
foreach ($img_data as $i => $attr_value)
{
$new_array[$i][$attr] = $attr_value;
}
}
答案 1 :(得分:1)
$newArray = array();
foreach($oldArray as $indexName=>$values) {
foreach($values as $index=>$value) {
$new = &$newArray[$index];
if(!isset($new))
$new = array();
$new[$indexName] = $value;
}
}
print_r($newArray);
或类似的东西。
答案 2 :(得分:0)
也许这会有所帮助......(考虑到$ actualArray是你的原始阵列......
$new = array();
foreach($actualArray as $kFather => $vFather) {
foreach ($vFather as $key => $value) {
$new[] = array($kFather => $value);
}
}
顺便说一句,别忘了使用','来分隔数组的元素