3v4l.org

run code in 500+ PHP versions simultaneously
<?php $arr = ['Format 10x10', 'Format 20x20', 'Format 100x100']; print "strnatcasecmp:\n"; usort($arr, 'strnatcasecmp'); var_dump($arr); print "\n\nstrcasecmp:\n"; usort($arr, 'strcasecmp'); var_dump($arr); print "\n\nCollator:\n"; $collator = new Collator('en'); // 2. Use usort with the collator's compare method usort($arr, [$collator, 'compare']); var_dump($arr); print "\n\nCollator (with numeric):\n"; $collator->setAttribute(Collator::NUMERIC_COLLATION, Collator::ON); // 2. Use usort with the collator's compare method usort($arr, [$collator, 'compare']); var_dump($arr);
Output for 8.4.16
strnatcasecmp: array(3) { [0]=> string(12) "Format 10x10" [1]=> string(12) "Format 20x20" [2]=> string(14) "Format 100x100" } strcasecmp: array(3) { [0]=> string(14) "Format 100x100" [1]=> string(12) "Format 10x10" [2]=> string(12) "Format 20x20" } Collator: array(3) { [0]=> string(14) "Format 100x100" [1]=> string(12) "Format 10x10" [2]=> string(12) "Format 20x20" } Collator (with numeric): array(3) { [0]=> string(12) "Format 10x10" [1]=> string(12) "Format 20x20" [2]=> string(14) "Format 100x100" }

preferences:
31.18 ms | 1137 KiB | 5 Q