[英]How to Sort Numerically Ascending with scandir()
Just like the question asks. 就像问题一样。 Does 5.4 address this?
5.4会解决这个问题吗?
array scandir ( string $directory [, int $sorting_order = SCANDIR_SORT_ASCENDING [, resource $context ]] )
but SCANDIR_SORT_ASCENDING
will not work properly with numerical names. 但
SCANDIR_SORT_ASCENDING
无法正确使用数字名称。 You can foreach items and then sort them with other function like this one: sort($array, SORT_NUMERIC)
您可以预先处理项目,然后使用其他功能对它们进行排序:
sort($array, SORT_NUMERIC)
Yes, I am using scandir(); 是的,我正在使用scandir(); To make it sort Descending rather than the default Ascending, use the int 1 or 0.
要使其降序排序而不是默认的升序,请使用int 1或0。
scandir(directory,sort,context); SCANDIR(目录,排序,上下文);
for example: 例如:
$dir = "./portfolio";
$files = scandir($dir, 1);
w3schools: http://www.w3schools.com/php/func_directory_scandir.asp w3schools: http : //www.w3schools.com/php/func_directory_scandir.asp
Yes, see docs http://php.net/manual/en/function.scandir.php 是的,请参阅文档http://php.net/manual/en/function.scandir.php
As of version 5.4.0 从版本5.4.0开始
sorting_order now accepts constants.
sorting_order现在接受常量。 Any nonzero value caused descending order in previous versions.
任何非零值都会导致先前版本中的降序排列。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.