note 37129 added to function.asort
| From: | siggi at rn2 dot php dot net | Date: | Tue, 04 Nov 2003 11:56:08 +0000 |
| Subject: | note 37129 added to function.asort | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-59855@lists.php.net to get a copy of this message | ||
Much simpler (imho) way to sort an array and preserve key sorting. Not sure though whether this is
faster than the previous method for large (> 1000) arrays.
$fruits=
array('apple','banana','banana','lemon','apple');
$temp = array();
foreach($tmp AS $Key => $Value) {
$temp[$Value][] = $Key;
}
ksort($temp);
$fruits= Array();
foreach($temp AS $Value => $Keys) {
asort($Keys);
foreach($Keys AS $Val) {
$fruits[$Val] = $Value;
}
}
unset($temp);
----
Manual Page -- http://www.php.net/manual/en/function.asort.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+37129
Delete -- http://master.php.net/manage/user-notes.php?action=delete+37129&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+37129&report=yes
Search -- http://master.php.net/manage/user-notes.php