By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,918 Members | 1,923 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,918 IT Pros & Developers. It's quick & easy.

Sort order of a sorted array

P: n/a
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
Dec 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Stefan Mueller wrote:


Reply posted in alt.php
JW
Dec 18 '05 #2

P: n/a
On Sat, 17 Dec 2005 21:36:50 +0100, Stefan Mueller wrote:
With the PHP command 'sort' I can sort an array


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

Dec 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.