SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    Feb 2004
    Location
    Rome
    Posts
    296
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    array sorting problem

    Hello

    My array $files contains a list of name files like this

    1.txt
    2.txt
    3.txt
    ...
    10000.txt


    If I sort the array sort($files) I receive this for example

    8809.txt
    881.txt
    8822.txt

    but I would have this instead ..!

    881.txt
    8809.txt
    8822.txt

    How to solve ?

    Thanks

  2. #2
    SitePoint Addict
    Join Date
    Feb 2004
    Location
    Rome
    Posts
    296
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok found , natsort is the solution
    http://it.php.net/manual/en/function.natsort.php

  3. #3
    SitePoint Addict
    Join Date
    Feb 2004
    Location
    Rome
    Posts
    296
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if I would sort in inverse order ? from 10000.eml to 1.eml what to do please ?

  4. #4
    Keep it simple, stupid! bokehman's Avatar
    Join Date
    Jul 2005
    Posts
    1,935
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ascending:
    PHP Code:
    sort($filesSORT_NUMERIC); 
    Descending:
    PHP Code:
    rsort($filesSORT_NUMERIC); 

  5. #5
    SitePoint Addict
    Join Date
    Feb 2004
    Location
    Rome
    Posts
    296
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks!


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
  •