Created
August 7, 2010 09:22
-
-
Save 0xnbk/512622 to your computer and use it in GitHub Desktop.
natsort()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$items = array( | |
"100 apples", "5 apples", "110 apples", "55 apples" | |
); | |
// normal sorting: | |
sort($items); | |
print_r($items); | |
# Outputs: | |
# Array | |
# ( | |
# [0] => 100 apples | |
# [1] => 110 apples | |
# [2] => 5 apples | |
# [3] => 55 apples | |
# ) | |
natsort($items); | |
print_r($items); | |
# Outputs: | |
# Array | |
# ( | |
# [2] => 5 apples | |
# [3] => 55 apples | |
# [0] => 100 apples | |
# [1] => 110 apples | |
# ) | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
natsort() is a function which will sort items in an array naturally (ie, in an order which seems logical to a person), rather than by characters’ ordinal values