我的代码已经通过$ _FILES数组并取消设置了一些文件。该数组现在具有不以零开始并且也没有顺序的键。php更改多维数组的键
[userfile] => Array
(
[name] => Array
(
[2] => IMG_20170325_124043610_HDR.jpg
[3] => video_icon.png
[5] => watersports.gif
[7] => IMG_20170325_153726906_HDR.jpg
)
我想重新命名从零依次启动键,就像这样:
[userfile] => Array
(
[name] => Array
(
[0] => IMG_20170325_124043610_HDR.jpg
[1] => video_icon.png
[2] => watersports.gif
[3] => IMG_20170325_153726906_HDR.jpg
)
我不想改变[userfile的] [名]或键值任何其他非数字键。有这个功能吗?我想沿着这些线路做一些事情:
// FILE COUNT IS PROVIDED BY CODE ABOVE
// Is $num equal to $fileCount?
$num = 0;
// Change the value of the key through iteration
while ($num < $fileCount) {
// need a built in function that allows the key change
**reset_key**($_FILES['userfile']['name'][$num]);
**reset_key**($_FILES['userfile']['type'][$num]);
**reset_key**($_FILES['userfile']['tmp_name'][$num]);
**reset_key**($_FILES['userfile']['error'][$num]);
**reset_key**($_FILES['userfile']['size'][$num]);
}
$num++;
这甚至正确的方法,或者我应该被人在这里想什么?非常感谢您的投入!
干杯,
沙克尔顿
那么,为什么要重命名的键? –
我真的不知道为什么,但是如果你想重置键,你可以像'$ arr = array_values($ arr);'那样做。例如:[https://3v4l.org/K5evY](https://3v4l.org/K5evY) – FirstOne
[重置数组元素在PHP中的键?](http://stackoverflow.com/questions/10492839/reset-keys-of-array-elements-in-php) –