note 71344 added to function.asort
| From: | richard at happymango dot me dot uk | Date: | Thu, 23 Nov 2006 11:52:42 +0000 |
| Subject: | note 71344 added to function.asort | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-120020@lists.php.net to get a copy of this message | ||
This is a fixed version of the same function I posted below. Now it will handle duplicate entries in
the sorted field. EG: If there were two records that had the name Heathrow it would still work.
<?php
function record_sort($records, $field, $reverse=false)
{
$hash = array();
foreach($records as $key => $record)
{
$hash[$record[$field].$key] = $record;
}
($reverse)? krsort($hash) : ksort($hash);
$records = array();
foreach($hash as $record)
{
$records []= $record;
}
return $records;
}
?>
----
Server IP: 83.138.144.80
Probable Submitter: 80.194.36.8
----
Manual Page -- http://www.php.net/manual/en/function.asort.php
Edit -- https://master.php.net/note/edit/71344
Del: integrated -- https://master.php.net/note/delete/71344/integrated
Del: useless -- https://master.php.net/note/delete/71344/useless
Del: bad code -- https://master.php.net/note/delete/71344/bad+code
Del: spam -- https://master.php.net/note/delete/71344/spam
Del: non-english -- https://master.php.net/note/delete/71344/non-english
Del: in docs -- https://master.php.net/note/delete/71344/in+docs
Del: other reasons-- https://master.php.net/note/delete/71344
Reject -- https://master.php.net/note/reject/71344
Search -- https://master.php.net/manage/user-notes.php