[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 268
  • Last Modified:

Sorting Arrays

What are the commands for sorting arrays ?
Thanks,
Michael
0
mhoggatt1
Asked:
mhoggatt1
4 Solutions
 
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
 
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now