Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Oct 2003
    Location
    AZ
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts

    sorting an array with natcasesort()

    I have an array of directory names. sort() works fine but isn't case insensitive. So I am wanting to use natcasesort() but it's not sorting in any logical order that I can see. How can I sort this array case insensitive? >

    This is the array BEFORE natcasesort():
    Array
    (
    [manual] => Array
    (
    [name] => manual
    [details] =>
    )

    [journal] => Array
    (
    [name] => journal
    [details] =>
    )

    [stress_buster] => Array
    (
    [name] => stress_buster
    [details] =>
    )

    [pocket_guide] => Array
    (
    [name] => pocket_guide
    [details] =>
    )

    [Qcodes] => Array
    (
    [name] => Qcodes
    [details] =>
    )

    [disc_wallet] => Array
    (
    [name] => disc_wallet
    [details] =>
    )

    [bread_and_butter] => Array
    (
    [name] => bread_and_butter
    [details] =>
    )

    [big_seminar] => Array
    (
    [name] => big_seminar
    [details] =>
    )

    [uploads] => Array
    (
    [name] => uploads
    [details] =>
    )

    [practitioner_training] => Array
    (
    [name] => practitioner_training
    [details] =>
    )

    [success_codes] => Array
    (
    [name] => success_codes
    [details] =>
    )

    [mp3] => Array
    (
    [name] => mp3
    [details] =>
    )

    [truth_tech] => Array
    (
    [name] => truth_tech
    [details] =>
    )

    [3_inch_sticker] => Array
    (
    [name] => 3_inch_sticker
    [details] =>
    )

    [infomercial] => Array
    (
    [name] => infomercial
    [details] =>
    )

    [testimonials_2006] => Array
    (
    [name] => testimonials_2006
    [details] =>
    )

    [disc_label] => Array
    (
    [name] => disc_label
    [details] =>
    )

    [binder] => Array
    (
    [name] => binder
    [details] =>
    )

    )

    this is AFTER natcasesort(). Why is the order all messed up still?
    Array
    (
    [truth_tech] => Array
    (
    [name] => truth_tech
    [details] =>
    )

    [mp3] => Array
    (
    [name] => mp3
    [details] =>
    )

    [success_codes] => Array
    (
    [name] => success_codes
    [details] =>
    )

    [3_inch_sticker] => Array
    (
    [name] => 3_inch_sticker
    [details] =>
    )

    [infomercial] => Array
    (
    [name] => infomercial
    [details] =>
    )

    [binder] => Array
    (
    [name] => binder
    [details] =>
    )

    [disc_label] => Array
    (
    [name] => disc_label
    [details] =>
    )

    [testimonials_2006] => Array
    (
    [name] => testimonials_2006
    [details] =>
    )

    [practitioner_training] => Array
    (
    [name] => practitioner_training
    [details] =>
    )

    [uploads] => Array
    (
    [name] => uploads
    [details] =>
    )

    [pocket_guide] => Array
    (
    [name] => pocket_guide
    [details] =>
    )

    [stress_buster] => Array
    (
    [name] => stress_buster
    [details] =>
    )

    [journal] => Array
    (
    [name] => journal
    [details] =>
    )

    [Qcodes] => Array
    (
    [name] => Qcodes
    [details] =>
    )

    [disc_wallet] => Array
    (
    [name] => disc_wallet
    [details] =>
    )

    [big_seminar] => Array
    (
    [name] => big_seminar
    [details] =>
    )

    [bread_and_butter] => Array
    (
    [name] => bread_and_butter
    [details] =>
    )

    [manual] => Array
    (
    [name] => manual
    [details] =>
    )

    )
    PHP | FreeBSD | MySQL |
    Check documentation... check documentation again and actually read it..do it... doesn't work ask.

  • #2
    New Coder
    Join Date
    Aug 2005
    Location
    Edmonton, Canada
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts
    http://ca3.php.net/manual/en/function.natcasesort.php

    PHP Code:
    <?php
    $array1 
    $array2 = array('IMG0.png''img12.png''img10.png''img2.png''img1.png''IMG3.png');

    sort($array1);
    echo 
    "Standard sorting\n";
    print_r($array1);

    natcasesort($array2);
    echo 
    "\nNatural order sorting (case-insensitive)\n";
    print_r($array2);
    ?>


    Standard sorting
    Array
    (
        [0] => IMG0.png
        [1] => IMG3.png
        [2] => img1.png
        [3] => img10.png
        [4] => img12.png
        [5] => img2.png
    )

    Natural order sorting (case-insensitive)
    Array
    (
        [0] => IMG0.png
        [4] => img1.png
        [3] => img2.png
        [5] => IMG3.png
        [2] => img10.png
        [1] => img12.png
    )

  • #3
    New Coder
    Join Date
    Oct 2003
    Location
    AZ
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes i've read that many times.

    the second array i posted is the result i get with natcasesort(); which is not any kind of sorting.
    PHP | FreeBSD | MySQL |
    Check documentation... check documentation again and actually read it..do it... doesn't work ask.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •