原数组$arr1的数据结构为:
array(1) { ["pic"]=> array(5) { ["name"]=> array(4) { [0]=> string(9) "icon1.png" [1]=> string(9) "icon2.png" [2]=> string(9) "icon3.png" [3]=> string(9) "icon4.png" } ["type"]=> array(4) { [0]=> string(9) "image/png" [1]=> string(9) "image/png" [2]=> string(9) "image/png" [3]=> string(9) "image/png" } ["tmp_name"]=> array(4) { [0]=> string(27) "C:WindowsTempphpA04F.tmp" [1]=> string(27) "C:WindowsTempphpA050.tmp" [2]=> string(27) "C:WindowsTempphpA051.tmp" [3]=> string(27) "C:WindowsTempphpA052.tmp" } ["error"]=> array(4) { [0]=> int(0) [1]=> int(0) [2]=> int(0) [3]=> int(0) } ["size"]=> array(4) { [0]=> int(1815) [1]=> int(1502) [2]=> int(3953) [3]=> int(2435) } } }
要将其数据结构形式改为如下:
array(1) { ["pic"]=> array(4) { [0]=> array(5) { ["name"]=> string(9) "icon1.png" ["type"]=> string(9) "image/png" ["tmp_name"]=> string(27) "C:WindowsTempphpA04F.tmp" ["error"]=> int(0) ["size"]=> int(1815) } [1]=> array(5) { ["name"]=> string(9) "icon2.png" ["type"]=> string(9) "image/png" ["tmp_name"]=> string(27) "C:WindowsTempphpA050.tmp" ["error"]=> int(0) ["size"]=> int(1502) } [2]=> array(5) { ["name"]=> string(9) "icon3.png" ["type"]=> string(9) "image/png" ["tmp_name"]=> string(27) "C:WindowsTempphpA051.tmp" ["error"]=> int(0) ["size"]=> int(3953) } [3]=> array(5) { ["name"]=> string(9) "icon4.png" ["type"]=> string(9) "image/png" ["tmp_name"]=> string(27) "C:WindowsTempphpA052.tmp" ["error"]=> int(0) ["size"]=> int(2435) } } }
更改方法为:
$arr2=array(); foreach ($arr1['pic'] as $key01 => $val01) { foreach ($val01 as $key02 => $val02) { $arr2['pic'][$key02][$key01]=$val02; } } echo "<pre>"; var_dump($arr2); echo "</pre>";