Array (
[item_file] => Array (
[name] => Array (
[0] => redphotonzillion1.jpg
[1] => redphotonzillion2.jpg
[2] => redphotonzillion3.jpg
[3] => redphotonzillion4.jpg
[4] => redphotonzillion5.jpg
[5] => redphotonzillion6.jpg
)
[type] => Array (
[0] => image/jpeg
[1] => image/jpeg
[2] => image/jpeg
[3] => image/jpeg
[4] => image/jpeg
[5] => image/jpeg
)
[tmp_name] => Array (
[0] => /var/www/clients/client0/web6/tmp/phpi4i5fE
[1] => /var/www/clients/client0/web6/tmp/phpzHwagk
[2] => /var/www/clients/client0/web6/tmp/phpYpAgg0
[3] => /var/www/clients/client0/web6/tmp/phpAIdngG
[4] => /var/www/clients/client0/web6/tmp/phpyamugm
[5] => /var/www/clients/client0/web6/tmp/phpFvWBg2
)
[error] => Array (
[0] => 0
[1] => 0
[2] => 0
[3] => 0
[4] => 0
[5] => 0
)
[size] => Array (
[0] => 7990
[1] => 8985
[2] => 8014
[3] => 7621
[4] => 7023
[5] => 7151
)
)
)
我想要的是按名称排序这个数组
答案 0 :(得分:1)
对于这种特定情况,PHP提供了正确的功能:array_multisort()
:
它可以对多维数组(或多个平面数组)进行排序,首先对第一个数组进行排序,然后将结果顺序应用于所有其他数组(例如,请参阅documentation)。
array_multisort(
// Array used to sort + optional parameters
$_FILES['item_file']['name'], SORT_ASC, SORT_STRING
// All other arrays to be sorted in the same order
$_FILES['item_file']['type'],
$_FILES['item_file']['tmp_name'],
$_FILES['item_file']['error'],
$_FILES['item_file']['size']
);
此aproach会将所有元信息(type
,tmp_name
,error
,size
)分配到文件name
的相应索引,以便它可以使用。