SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Evangelist
    Join Date
    Jul 2002
    Location
    Italy
    Posts
    448
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    scandir() sorting

    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
    PHP Code:
    scandir($yearsSCANDIR_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
    blessed are the cracked for they let in the light

  2. #2
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    England
    Posts
    698
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I've seen this before. Check that the SCANDIR_SORT_DESCENDING constant has been defined:
    Code PHP:
    Look for that constant (or any beginning with SCANDIR_)

  3. #3
    SitePoint Evangelist
    Join Date
    Jul 2002
    Location
    Italy
    Posts
    448
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Antnee. It looks like the SCANDIR constants are not set.
    blessed are the cracked for they let in the light

  4. #4
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    England
    Posts
    698
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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!)

  5. #5
    SitePoint Evangelist
    Join Date
    Jul 2002
    Location
    Italy
    Posts
    448
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh. I thought the manual said the integer values were added in 5.4 and I thought that I couldn't use them! Guess I read that the manual wrong...
    blessed are the cracked for they let in the light

  6. #6
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    England
    Posts
    698
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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

  7. #7
    SitePoint Evangelist
    Join Date
    Jul 2002
    Location
    Italy
    Posts
    448
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Many thanks for your useful explanation. G
    blessed are the cracked for they let in the light

  8. #8
    SitePoint Evangelist captainccs's Avatar
    Join Date
    Mar 2004
    Location
    Caracas, Venezuela
    Posts
    516
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You could use this code:
    PHP Code:
    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

    Denny Schlesinger
    web services

  9. #9
    SitePoint Evangelist
    Join Date
    Jul 2002
    Location
    Italy
    Posts
    448
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Denny - that's useful. G
    blessed are the cracked for they let in the light


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •