# Sort order of a sorted array

#### Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

•  Subject
• Author
• Posted on
With the PHP command 'sort' I can sort an array. However, it doesn't exactly
sort the array I'd like to:

<html>
<body>
<?php
\$my_array[0] = array("AA", "11");
\$my_array[1] = array("AA", "22");
\$my_array[2] = array("aa", "22");
\$my_array[3] = array("AB", "11");
\$my_array[4] = array("ab", "11");
\$my_array[5] = array("ab", "22");
\$my_array[6] = array("b", "11");
\$my_array[7] = array("ab", "33");
\$my_array[8] = array("bb", "11");
\$my_array[9] = array("eb", "11");
\$my_array[10] = array("b", "11");
\$my_array[11] = array("fa", "11");

sort(\$my_array);

for (\$i = 0; \$i <= 11; \$i++) {
echo \$my_array[\$i][0] . " / " . \$my_array[\$i][1] . "<br>";
}
?>
</body>
</html>

=========================

Result:
AA / 11
AA / 22
AB / 11
aa / 22
ab / 11
ab / 22
ab / 33
bb / 11
eb / 11
fa / 11
b / 11
b / 11

Requested result:
AA / 11
AA / 22
aa / 22
AB / 11
ab / 11
b / 11
ab / 22
ab / 33
bb / 11
eb / 11
b / 11
fa / 11

Is it somehow possible to tell sort that it has to handle 'A' like 'a' and
also '' like 'a' (like 'latin_german1_ci' in MySQL)?

Stefan

## Re: Sort order of a sorted array

Stefan Mueller wrote:

JW

## Re: Sort order of a sorted array

On Sat, 17 Dec 2005 21:36:50 +0100, Stefan Mueller wrote:

You can try usort function to which you have to provide sort function.
If you want to sort array by key, you can try with uksort.

--
http://www.mgogala.com