php如何反向排列数组,php中的sort()如何排列目录结构数组?

我正在从官方手册中学习php,刚刚学习了Arrays部分的示例#13

https://www.php.net/manual/en/language.types.array.php

当我从命令行使用php localserver在本地windows 10中运行示例代码时

sort()

实际上是不排序数组。我尝试了以下代码:

// fill an array with all items from a directory

$handle = opendir('.');

while (false !== ($file = readdir($handle))) {

$files[] = $file;

}

print_r($files);

sort($files);

print_r($files);

closedir($handle);

?>

我得到的输出如下:

Array

(

[0] => .

[1] => ..

[2] => .ftpquota

[3] => Ftp fxg710ehhrpx.xml

[4] => index.html

[5] => index.php

[6] => Logo

[7] => myphp

[8] => OnlineSlap.rar

)

Array

(

[0] => .

[1] => ..

[2] => .ftpquota

[3] => Ftp fxg710ehhrpx.xml

[4] => Logo

[5] => OnlineSlap.rar

[6] => index.html

[7] => index.php

[8] => myphp

)

如你所见,在使用之前

sort

数组按字母顺序排列,但在

排序()

顺序变得随机。

为什么阵列

unsorted

预期的行为是什么?

谢谢您。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值