1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

readdir() sort in php

Discussion in 'HTML, Graphics & Programming' started by shady, 24 May 2006.

  1. shady

    Hitman

    Joined: 4 Nov 2002

    Posts: 905

    Location: NE Scotland

    I'm having great difficulty sorting an array in php. Can anybody help me please:


    Code:
    echo "  var pixList=new Array();\n";
    $dir=opendir($albums_root_dir."/".$album_dir);
    $i=0;
    while($entry=readdir($dir)) if(is_image($albums_root_dir."/".$album_dir."/".$entry)){
    
      echo "  pixList[".$i."]=".get_MAImage($albums_root_dir."/".$album_dir."/".$entry,$max_miniature_width,$max_miniature_height,'').";\n";
      echo "  pixList[".($i++)."].imageFile='".$entry."'\n;";
     
    Last edited: 24 May 2006
  2. Dj_Jestar

    Caporegime

    Joined: 18 Oct 2002

    Posts: 28,940

    Location: Back in East London

    Code:
    USE CODE TAGS!
     
  3. Sic

    Capodecina

    Joined: 9 Nov 2004

    Posts: 15,365

    Location: SO16

    readdir() doesnt actually (seem to) read the contents of a directory into an array. it reads through a directory in the order that the file system lists it, after opening with opendir().

    take a look at those sections of the PHP manual and if you're still having trouble after that, post back :)
     
  4. robmiller

    Capodecina

    Joined: 26 Dec 2003

    Posts: 16,522

    Location: London

    Code:
    $files = glob('*');
    natsort($files);
    
    var_dump($files);