note 72372 added to function.natsort
| From: | lacent at gmail dot com | Date: | Tue, 16 Jan 2007 17:42:38 +0000 |
| Subject: | note 72372 added to function.natsort | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-121802@lists.php.net to get a copy of this message | ||
there is another rnatsort function lower on the page, but it didn't work in the context i
needed it in.
reasoning for this:
sorting naturally via the keys of an array, but needing to reverse the order.
function rnatsort ( &$array = array() )
{
$keys = array_keys($array);
natsort($keys);
$total = count($keys) - 1;
$temp1 = array();
$temp2 = array();
// assigning original keys to an array with a backwards set of keys, to use in krsort();
foreach ( $keys as $key )
{
$temp1[$total] = $key;
--$total;
}
ksort($temp1);
// setting the new array, with the order from the krsort() and the values of original array.
foreach ( $temp1 as $key )
{
$temp2[$key] = $array[$key];
}
$array = $temp2;
}
----
Server IP: 64.71.164.2
Probable Submitter: 216.136.83.246
----
Manual Page -- http://www.php.net/manual/en/function.natsort.php
Edit -- https://master.php.net/note/edit/72372
Del: integrated -- https://master.php.net/note/delete/72372/integrated
Del: useless -- https://master.php.net/note/delete/72372/useless
Del: bad code -- https://master.php.net/note/delete/72372/bad+code
Del: spam -- https://master.php.net/note/delete/72372/spam
Del: non-english -- https://master.php.net/note/delete/72372/non-english
Del: in docs -- https://master.php.net/note/delete/72372/in+docs
Del: other reasons-- https://master.php.net/note/delete/72372
Reject -- https://master.php.net/note/reject/72372
Search -- https://master.php.net/manage/user-notes.php