As you know, the sort() funtion will sort arays like this

Acorns
Bees
Birds
Cows
apples
rocks

I need to sort my arrays like this

Acorns
apples
Bees
Birds
Cows
rocks

I've tried natcasesort() but it's querky.. I haven't looked in to it very far but.. it destoys some array enteries? I also tried using sort(strtolower($array)) but that gave me wrong data type.. as expected. Too bad there isn't a arraytolower() funtion? Is there?

Any advice is apreciated 🙂

    Why don't you first change all the strings into upper, lower case or uc-first?

    You don't have any problem with sorting an array any more.

      It would look ugly. It's not simple data.. it's for a catalouge. I need to maintain case indefernce.

      Thanks though..

      Can anyone help?

        why don't you use the usort function and write a quick little function that makes a lowercase temp value for each array element and uses that to sort?

          OR, he could RTFM and use the natcasesort() function. grin

            What is RTFM? I tried natcasesort() it causes me problems ^ read first entery.

            Nate, could you give me an example of how to do what you were saying about the temp array? I was thinking of doing somthing like that but I'm still a newb and don't quite know how.

            Thanks,

            Zeek

              rtfm means read the fucking manual.

              another solutions is to create a new array.

              looks like this:

              $product = array(0 => 'Acorns', 1=> 'Bees', 2 =>'Birds', 3 => 'Cows', 4 => 'apples', 5 => 'rocks');
              natcasesort($product);
              $new_array= array();

              while (list ($key, $val) = each ($product)) {
              array_push($new_array, $val);
              }

              print_r($new_array);

                If you read my first entery you'll see that I did RTFM. natcasesort() is causing me problems.. I was asking if it's the way to go. I guess so. I'll have to spend some time tring to figure out why natcasesort() is making magical things happen to my arrays.

                  Sorry, i tried it on a local system here and it's works perfect.

                  just make that new array.

                    I guess that natcasesort() is the way to go.. it's probably other parts of my script that are failing because I use this function.. and not the function it's self.

                      Didn't quite get what you meant by create a new array.. but now I do.

                      Here's some out put from some DEBUG info I wrote to my self

                      DEBUG: Array Before

                      Array ( [0] => Compound Liquid Extracts [1] => Grapefruit Seed Extract Products [2] => Simple Liquid Extracts [3] => Single Bulk Dried Herbs [4] => bug )

                      DEBUG: Array After

                      Array ( [4] => bug [0] => Compound Liquid Extracts [1] => Grapefruit Seed Extract Products [2] => Simple Liquid Extracts [3] => Single Bulk Dried Herbs )

                      DEBUG: Array After After

                      Array ( [0] => bug [1] => Compound Liquid Extracts [2] => Grapefruit Seed Extract Products [3] => Simple Liquid Extracts [4] => Single Bulk Dried Herbs )

                      What I really needed explaining to me was that natcasesort() screws up the index numbers. the Array After After is a new array like you said to do 🙂

                      Thanks for the help!

                        natural sorting doesn't chance the key & value pairs it's only sorting them on the value pair.

                        by makeing a new array from the natural the key & value pairs are assigned again in a proper way.

                        that's way you have to make a new array.

                          Write a Reply...