note 53588 deleted from function.sort by derick
| From: | derick@php.net | Date: | Wed, 31 Aug 2005 10:41:48 +0000 |
| Subject: | note 53588 deleted from function.sort by derick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-94512@lists.php.net to get a copy of this message | ||
Note Submitter: Jens Weber
----
I had always problems sorting a array with many items.
The given php-functions couldn't sort the array correctly,
so I decided to write an own function:
This function sorts over 100 items correctly
(also if there are values with special signs):
<?php
//Array-Sort for an Array with textvalues
function array_sort($array)
{
foreach($array as $wert)
{
$bereich=strtolower(substr($wert,0,1));
$add[$bereich][strtolower($wert)]=$wert;
}
$key=array_keys($add);
sort($key,SORT_STRING);
for($x=0;$x<count($key);$x++)
{
$akt=$add[$key[$x]];
ksort($akt,SORT_REGULAR);
foreach($akt as $wert)
{
$out[]=$wert;
}
}
return $out;
}
?>
MFG
Jens
Contact: http://weltie.com