13
Jul '12
Natural String Comparison in PHP
I’ve recently discovered two string comparison and sorting functions for the first time that really made my life easier:
The first is is natsort which is an alternative to sort. It sorts an using a natural language metric e.g. It could produce the sorted order of 1, 2, 3, 10, 11, 12 whereas a normal sort would produce 1, 10, 11, 12, 2, 3.
The second is strnatcmp which is an alternative to strcmp. It applies the same natural language approach as above to comparison operations.