note 107183 added to function.natsort
| From: | Trevor at osu1 dot php dot net | Date: | Thu, 12 Jan 2012 23:02:37 +0000 |
| Subject: | note 107183 added to function.natsort | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-185623@lists.php.net to get a copy of this message | ||
jonathan_2097 wrote:
natsort by key
<?php
function knatsort($array)
{
return array_flip(natsort(array_flip($array));
}
?>
This won't work if you array has duplicate values! Array_flip will cause key collisions and
that would be bad. Instead, use
<?php
uksort($array,"strnatcmp");
?>
----
Server IP: 69.147.83.197
Probable Submitter: 68.116.170.225
----
Manual Page -- http://www.php.net/manual/en/function.natsort.php
Edit -- https://master.php.net/note/edit/107183
Del: integrated -- https://master.php.net/note/delete/107183/integrated
Del: useless -- https://master.php.net/note/delete/107183/useless
Del: bad code -- https://master.php.net/note/delete/107183/bad+code
Del: spam -- https://master.php.net/note/delete/107183/spam
Del: non-english -- https://master.php.net/note/delete/107183/non-english
Del: in docs -- https://master.php.net/note/delete/107183/in+docs
Del: other reasons-- https://master.php.net/note/delete/107183
Reject -- https://master.php.net/note/reject/107183
Search -- https://master.php.net/manage/user-notes.php