natsort
PHP 4, PHP 5, PHP 7, PHP 8
natsort - Sort an array using a "natural order" algorithm
Example #1 natsort examples demonstrating basic usage
Result: Standard sorting
Array
(
[3] => img1.png
[1] => img10.png
[0] => img12.png
[2] => img2.png
)
Natural order sorting
Array
(
[3] => img1.png
[2] => img2.png
[1] => img10.png
[0] => img12.png
)
Example #2 natsort examples demonstrating potential gotchas
Result: Negative numbers
Array
(
[0] => -5
[1] => 3
[2] => -2
[3] => 0
[4] => -1000
[5] => 9
[6] => 1
)
Array
(
[2] => -2
[0] => -5
[4] => -1000
[3] => 0
[6] => 1
[1] => 3
[5] => 9
)
Zero padding
Array
(
[0] => 09
[1] => 8
[2] => 10
[3] => 009
[4] => 011
[5] => 0
)
Array
(
[5] => 0
[1] => 8
[3] => 009
[0] => 09
[2] => 10
[4] => 011
)
Example #3 of natsort