1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

array sort help

Discussion in 'PHP' started by blueseraph, Sep 3, 2007.

  1. #1
    need some help with a script to sort images for a gallery.
    I have the thumbnails in a dir and need to display them in the order that you would see them in windows.

    here is my code:

    'gets all thubnails from the dir'

    $dirtoopen="artist/".$galName;
    $tn=0;
    if ($handle = opendir($dirtoopen)) {

    while (false !== ($file = readdir($handle))) {
    if ($file != "." && $file != "..") {
    $tn++;
    $tNF[$tn]=$file;
    }
    }
    closedir($handle);

    The order that they are retrieved in is not the same order that I view them in ftp or within windows. I have added sort($tNF); after the closedir($handle); but the orde3r still isn't right. With the sort it displayes numbers (070706a) then jumps to letters (Untitled-03-09-2007) then underscores (_63) and finally back to letters (a15 ) here is a list of how it is outputing the sorted array.

    3d1, 3d2, 3d3small, 3d4, Untitled-111, Untitled-1a, Untitled-1b, Untitled-1f, Untitled-1nnn , Untitled-38-copya, Untitled-38, Untitled-4-copya-redo, Untitled-51, Untitled-52, Untitled-54, Untitled-55, art5a, art7, cs5, ff02, ff03, ff04, ff05, ff06, hane-1, k1, k2

    Please help me figure out how to sort them (_,00-99,aA-zZ)

    This is what is currently outputing:

    Untitled-05,
    Untitled-1cs3a-better,
    Untitled-38,
    Untitled-41,
    _6A,
    art12-copy,
    cs4,
    fractal-apple,
    hane-1,
    objects

    And this is what it should be:

    _6A,
    art12-copy,
    cs4,
    fractal-apple,
    hane-1,
    objects,
    Untitled-1cs3a-better,
    Untitled-05,
    Untitled-38,
    Untitled-41,
     
    blueseraph, Sep 3, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    natsort($tNF);
    
    PHP:
     
    nico_swd, Sep 3, 2007 IP
  3. blueseraph

    blueseraph Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    natsort($tNF) outputs

    (broken link)-should be 'Untitled-05'
    Untitled-41
    objects
    art12-copy
    fractal-apple
    Untitled-1cs3a-better
    cs4
    hane-1
    Untitled-38
    _6A
     
    blueseraph, Sep 3, 2007 IP
  4. blueseraph

    blueseraph Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    does anyone know how to use the usort function? I think that might work but I have no idea how to create the user defined comparison.
     
    blueseraph, Sep 3, 2007 IP