Array sorting for strings
Posted: Tue Dec 30, 2003 3:03 am
I am facing a problem while sorting the strings in arrays.
The problem is that the upper case characters are sorted before the lower case characters. This is perhaps because the sorting is done based on ascii values of the characters.
Foll. is the code snippet that we are using for sorting.
<?php
$ar = array (array ('anna', 'bird', 'Anu', 'king'), array (1, 3, "2", 1));
array_multisort ($ar[0], SORT_ASC, SORT_NUMERIC,
$ar[1], SORT_STRING, SORT_DESC);
foreach ($ar as $k=>$v)
{
foreach ($v as $key=>$val)
echo "At ".key." is ".$val."<br>";
}
?>
Can anyone pls. suggest the solution?
Thanks in advance.
Shantanu.
The problem is that the upper case characters are sorted before the lower case characters. This is perhaps because the sorting is done based on ascii values of the characters.
Foll. is the code snippet that we are using for sorting.
<?php
$ar = array (array ('anna', 'bird', 'Anu', 'king'), array (1, 3, "2", 1));
array_multisort ($ar[0], SORT_ASC, SORT_NUMERIC,
$ar[1], SORT_STRING, SORT_DESC);
foreach ($ar as $k=>$v)
{
foreach ($v as $key=>$val)
echo "At ".key." is ".$val."<br>";
}
?>
Can anyone pls. suggest the solution?
Thanks in advance.
Shantanu.