I’m trying to use scandir() to sort in descending order but I’m not clear from the manual how to use the sort option. I’m running PHP v5.3.1 so I can’t use the numeric values. I have tried
scandir($years, SCANDIR_SORT_DESCENDING);
but get an error message:
Warning: scandir() expects parameter 2 to be long, string given in C:\xampp\htdocs\www\ifold\minutes.php on line 26
Thanks G
Thought so. They were added in PHP 5.4, so you’ll need to use the integer values. 0 is ascending, 1 is descending IIRC (why I didn’t just ask whether you were using PHP 5.4 or not I have no idea!)
When you have these functions with constants associated with sorting orders etc, they’re always just passing a value that you could enter directly. However, the values of these constants MAY change, which is why it’s better to use the constant. Constants will always follow (or appear at the same time) as the integer values
if(!defined("SCANDIR_SORT_ASCENDING")) {
define("SCANDIR_SORT_ASCENDING", 0);
}
if(!defined("SCANDIR_SORT_DESCENDING")) {
define("SCANDIR_SORT_DESCENDING", 1);
} else {
// send me an email telling me this code is no longer needed
}