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.
Array sorting for strings
Moderator: General Moderators
natcasesort()
I know you can use:
[php_man]natcasesort()[/php_man]
I'm not certain how you would apply it to your current code. I'm not great with arrays. Since there are only two arrays...possibly sort them seperately? *shrug*
[php_man]natcasesort()[/php_man]
I'm not certain how you would apply it to your current code. I'm not great with arrays. Since there are only two arrays...possibly sort them seperately? *shrug*