我的代碼已經通過$ _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) –