【发布时间】:2019-11-28 09:15:00
【问题描述】:
我正在尝试按键分隔一些值。
我当前的数组是这样的
Array
(
[name] => Array
(
[0] => test1
[1] => test2
)
[type] => Array
(
[0] => image/jpeg
[1] => image/jpeg
)
[tmp_name] => Array
(
[0] => D:\xampp5\tmp\php5F43.tmp
[1] => D:\xampp5\tmp\php5F63.tmp
)
[error] => Array
(
[0] => 0
[1] => 0
)
[size] => Array
(
[0] => 49293
[1] => 20286
)
)
我预期的数组会是这样的
Array
(
[0] =>(
[name] => test1
[type] => image/jpeg
[tmp_name] => D:\xampp5\tmp\php5F43.tmp
[error] => 0
[size] => 49293
)
[1] =>(
[name] => test2
[type] => image/jpeg
[tmp_name] => D:\xampp5\tmp\php5F63.tmp
[error] => 0
[size] => 20286
)
)
为此我尝试过这样的
$files = array();
$i = 0;
foreach ($array as $key => $value) {
foreach ($value as $item) {
$files[$i][] = $item;
// echo '["'.$key.'"] - '.$item.'<br>';
$i++;
}
}
但它只是增加数组索引而不是在特定键下推送。
请提出我在这里错过的内容
【问题讨论】:
-
去掉$i,使用二级密钥。这些 0 和 1 显然需要成为新数组中 first 级别的键。
标签: php arrays multidimensional-array array-filter