note 117315 added to function.natsort
| From: | mvs dot php at gmail dot com | Date: | Wed, 20 May 2015 10:12:26 +0000 |
| Subject: | note 117315 added to function.natsort | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-202619@lists.php.net to get a copy of this message | ||
To naturally sort by array key, the uksort function can be used.
<?php
echo "Sort by keys\n";
$smoothie = array('orange' => 1, 'apple' => 1, 'yogurt' => 4,
'banana' => 4);
print_r($smoothie);
uksort( $smoothie, 'strnatcmp');
print_r($smoothie)
?>
Output:
Sort by keys
Array
(
[orange] => 1
[apple] => 1
[yogurt] => 4
[banana] => 4
)
Array
(
[apple] => 1
[banana] => 4
[orange] => 1
[yogurt] => 4
)
See http://php.net/manual/en/function.uksort.php
for more information about uksort and http://php.net/strnatcmp for usage of strnatcmp.
----
Server IP: 72.52.91.14
Probable Submitter: 124.168.75.230
----
Manual Page -- http://php.net/manual/en/function.natsort.php
Edit -- https://master.php.net/note/edit/117315
Del: integrated -- https://master.php.net/note/delete/117315/integrated
Del: useless -- https://master.php.net/note/delete/117315/useless
Del: bad code -- https://master.php.net/note/delete/117315/bad+code
Del: spam -- https://master.php.net/note/delete/117315/spam
Del: non-english -- https://master.php.net/note/delete/117315/non-english
Del: in docs -- https://master.php.net/note/delete/117315/in+docs
Del: other reasons-- https://master.php.net/note/delete/117315
Reject -- https://master.php.net/note/reject/117315
Search -- https://master.php.net/manage/user-notes.php