Results 1 to 3 of 3

Thread: Sort read directory with PHP

  1. #1
    Join Date
    May 2007
    Location
    England, UK
    Posts
    235
    Thanks
    3
    Thanked 6 Times in 6 Posts

    Default Sort read directory with PHP

    I have a PHP script that uses opendir() and readdir().

    I use a while loop to display the results as a list. This works fine on my localhost but not on my web server (displays them in a random order).

    Is there any function I can use to sort the results of the while statement (Alphabetically)?

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    In the while loop, place the current file in an array (let's call it the files[] array). After the while loop, you can use sort or ksort and echo each item in the array using a foreach loop.

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. The Following User Says Thank You to thetestingsite For This Useful Post:

    jc_gmk (02-20-2008)

  4. #3
    Join Date
    May 2007
    Location
    England, UK
    Posts
    235
    Thanks
    3
    Thanked 6 Times in 6 Posts

    Default

    Perfect, 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
  •