Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

Sorting Array

$
0
0

Greetings all,

 

I have a script that creates an array from a folder of images.

// Create Array
$files = array();
if( is_dir( $thumbs_dir ) ) {
  if( $handle = opendir( $thumbs_dir ) ) {
    while( ( $file = readdir( $handle ) ) !== false ) {
      if( $file != "." && $file != ".." ) {
        array_push( $files, $file );
      }
    }
    closedir( $handle );
  }
}

If I echo this array out into a table or what have you it lists them in a strange way.

 

4_Photo1.jpg

4_Photo11.jpg

4_Photo12.jpg

......and so on up to 19

4_Photo2.jpg

4_Photo21.jpg

4_Photo22.jpg

.....and so on up to 29

4_Photo3.jpg

4_Photo31.jpg

4_Photo32.jpg

 

As you can see the array comes out in, well, a numeric order but a weird one. Instead of loading 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, it loads like above 1, 11, 12, 13, 14, 15, 16, 17, 18, 19, 2, 21, 22.....

 

How can I go about sorting this so that it comes out how one would count normally? Preferably in reverse order, counting down would be better.

 

I tried:

sort( $files, SORT_NUMERIC );

 

But that got really messy and threw the order all over the place.

 

Best Regards,

Nightasy


Viewing all articles
Browse latest Browse all 13200

Trending Articles