note 107199 added to function.natsort
| From: | RuneImp at gmail dot com | Date: | Sat, 14 Jan 2012 04:17:44 +0000 |
| Subject: | note 107199 added to function.natsort | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-185643@lists.php.net to get a copy of this message | ||
A natural key sorting function that won't loose data. Using an array_flip technique might be
faster but can loose data if the initial values are not all unique.
<?php
/**
* keyNatSort does a natural sort via key on the supplied array.
*
* @param $array The array to natural sort via key.
* @param $saveMemory If true will delete values from the original array as it builds the sorted
array.
* @return Sorted array on success. Boolean false if sort failed or null if the object was not an
array.
*/
function keyNatSort($array, $saveMemory=false)
{
if(is_array($array))
{
$keys = array_keys($array);
if(natsort($keys))
{
$result = array();
foreach($keys as $key)
{
$result[$key] = $array[$key];
if($saveMemory)
unset($array[$key]);
}
}
else
$result = false;
}
else
$result = null;
return $result;
}
?>
----
Server IP: 208.69.120.55
Probable Submitter: 209.90.61.25
----
Manual Page -- http://www.php.net/manual/en/function.natsort.php
Edit -- https://master.php.net/note/edit/107199
Del: integrated -- https://master.php.net/note/delete/107199/integrated
Del: useless -- https://master.php.net/note/delete/107199/useless
Del: bad code -- https://master.php.net/note/delete/107199/bad+code
Del: spam -- https://master.php.net/note/delete/107199/spam
Del: non-english -- https://master.php.net/note/delete/107199/non-english
Del: in docs -- https://master.php.net/note/delete/107199/in+docs
Del: other reasons-- https://master.php.net/note/delete/107199
Reject -- https://master.php.net/note/reject/107199
Search -- https://master.php.net/manage/user-notes.php