note 39021 deleted from function.sort by nlopess
| From: | nlopess@php.net | Date: | Thu, 15 Jan 2004 14:39:14 +0000 |
| Subject: | note 39021 deleted from function.sort by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-63619@lists.php.net to get a copy of this message | ||
Note Submitter: Ternami
----
Another very simple way to sort a simpe array as Case INsensitive
(maybe it could be made even simpler, but i don't have high PHP knowledge)
<?php
function SortArray($array_old)
{
$c=count($array_old); // count elements in a variable
for ($i=0; $i<$c; $i++) $array_low[$i]=strtolower($array_old[$i]); // make a new, lower case,
array
sort ($array_low); // here is a true case insensitive sort
for ($i=0; $i<$c; $i++)
for ($i2=0; $i2<$c; $i2++)
if ($array_low[$i]==strtolower($array_old[$i2])) $array_low[$i2]=$array_old[$i]; // we want to
get the old case back
return $array_low;
}
$AnyArray = SortArray($AnyArray); // here is an example of how to use the function
?>