Page 1 of 1

Array sorting for strings

Posted: Tue Dec 30, 2003 3:03 am
by shan123
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.

natcasesort()

Posted: Tue Dec 30, 2003 4:18 am
by mwong
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* :?: