Array sorting for strings

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
shan123
Forum Newbie
Posts: 9
Joined: Tue Oct 21, 2003 11:04 pm

Array sorting for strings

Post 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.
mwong
Forum Commoner
Posts: 34
Joined: Sun Dec 28, 2003 2:58 am

natcasesort()

Post 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* :?:
Post Reply