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);
Output for 8.2.31 - 8.2.34, 8.3.0 - 8.3.35, 8.4.1 - 8.4.26
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" }
Output for 8.5.5 - 8.5.11
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: Fatal error: Uncaught Error: Class "Collator" not found in /in/ZbOPJ:13 Stack trace: #0 {main} thrown in /in/ZbOPJ on line 13
Process exited with code 255.

preferences:
34.22 ms | 1140 KiB | 9 Q