note 54319 added to function.ksort
| From: | ssb45 at cornell dot edu | Date: | Thu, 30 Jun 2005 11:58:04 +0000 |
| Subject: | note 54319 added to function.ksort | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-91198@lists.php.net to get a copy of this message | ||
The function that justin at booleangate dot org provides works well, but be aware that it is not a
drop-in replacement for ksort as is. While ksort sorts the array by reference and returns a status
boolean, natksort returns the sorted array, leaving the original untouched. Thus, you must use this
syntax:
$array = natksort($array);
If you want to use the more natural syntax:
$status = natksort($array);
Then use this modified version:
function natksort(&$array) {
$keys = array_keys($array);
natcasesort($keys);
foreach ($keys as $k) {
$new_array[$k] = $array[$k];
}
$array = $new_array;
return true;
}
----
Manual Page -- http://www.php.net/manual/en/function.ksort.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+54319
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54319&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54319&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54319&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54319&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54319&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54319&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+54319&report=yes
Search -- http://master.php.net/manage/user-notes.php