Sorting Arrays

What are the commands for sorting arrays ?
Thanks,
Michael
mhoggatt1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TomeeboyCommented:
If you're wanting to sort it alphabetically:

natcasesort($array);
0
TomeeboyCommented:
Keep in mind, that will keep the key/value relationships in place, so if you have the following array:

Array (
    [0] => Test
    [1] => Array
    [2] => Data
)

and sort it with natcasesort(), it will turn out like this:

Array (
    [1] => Array
    [2] => Data
    [0] => Test
)

It is also case insensitive.  For case sensitive, use natsort()

If you don't mind the keys and values being scrambled, then just use:

sort($array);

http://au3.php.net/manual/en/function.sort.php
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Brian BushSolutions ArchitectCommented:
They are:
<A HREF="http://www.php.net/manual/en/function.array-multisort.php">array_multisort</A>&nbsp;--&nbsp;Sort multiple or multi-dimensional arrays</DT><DT>
<A HREF="http://www.php.net/manual/en/function.arsort.php">arsort</A>&nbsp;--&nbsp;Sort an array in reverse order and maintain index association
<A HREF="http://www.php.net/manual/en/function.asort.php">asort</A>&nbsp;--&nbsp;Sort an array and maintain index association</DT><DT>
<A HREF="http://www.php.net/manual/en/function.krsort.php">krsort</A>&nbsp;--&nbsp;Sort an array by key in reverse order</DT><DT>
<A HREF="http://www.php.net/manual/en/function.ksort.php">ksort</A>&nbsp;--&nbsp;Sort an array by key</DT><DT>
<A HREF="http://www.php.net/manual/en/function.natcasesort.php">natcasesort</A>&nbsp;--&nbsp;Sort an array using a case insensitive "natural order" algorithm
<A HREF="http://www.php.net/manual/en/function.natsort.php">natsort</A>&nbsp;--&nbsp;Sort an array using a "natural order" algorithm
<A HREF="http://www.php.net/manual/en/function.rsort.php">rsort</A>&nbsp;--&nbsp;Sort an array in reverse order</DT><DT>
<A HREF="http://www.php.net/manual/en/function.sort.php">sort</A>&nbsp;--&nbsp;Sort an array</DT><DT>
<A HREF="http://www.php.net/manual/en/function.uasort.php">uasort</A>&nbsp;--&nbsp;Sort an array with a user-defined comparison function andmaintain index association
<A HREF="http://www.php.net/manual/en/function.uksort.php">uksort</A>&nbsp;--&nbsp;Sort an array by keys using a user-defined comparison function
<A HREF="http://www.php.net/manual/en/function.usort.php">usort</A>&nbsp;--&nbsp;Sort an array by values using a user-defined comparison function

--brian
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Brian BushSolutions ArchitectCommented:
That came out ugly.

http://www.php.net/manual/en/function.array-multisort.php
Sort multiple or multi-dimensional arrays

http://www.php.net/manual/en/function.arsort.php
Sort an array in reverse order and maintain index association

http://www.php.net/manual/en/function.asort.php
Sort an array and maintain index association

http://www.php.net/manual/en/function.krsort.php
Sort an array by key in reverse order

http://www.php.net/manual/en/function.ksort.php
Sort an array by key

http://www.php.net/manual/en/function.natcasesort.php
Sort an array using a case insensitive "natural order" algorithm

http://www.php.net/manual/en/function.natsort.php
Sort an array using a "natural order" algorithm

http://www.php.net/manual/en/function.rsort.php
Sort an array in reverse order

http://www.php.net/manual/en/function.sort.php
Sort an array

http://www.php.net/manual/en/function.uasort.php
Sort an array with a user-defined comparison function and maintain index association

http://www.php.net/manual/en/function.uksort.php
Sort an array by keys using a user-defined comparison function

http://www.php.net/manual/en/function.usort.php
Sort an array by values using a user-defined comparison function

Maybe that will be easier to read.
--brian
0
RoonaanCommented:
When you are linkdumping already, just send a link to the array function page :-)

-r-
0
mhoggatt1Author Commented:
Thanks for the replies. Thay were very helpful.
Michael
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.