3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $alternatives = array( 'foo' => 0, 'foo1' => 0, 'foo3' => 0, ); echo 'before sorting:'.PHP_EOL; print_r($alternatives); asort($alternatives, SORT_STRING); echo 'after sorting:'.PHP_EOL; print_r($alternatives); $keys = array_keys($alternatives); print_r($keys); sort($keys); print_r($keys); sort($keys, SORT_STRING); print_r($keys); sort($keys, SORT_NATURAL); print_r($keys);
based on rjbjk
Output for 7.0.0 - 7.2.0
before sorting: Array ( [foo] => 0 [foo1] => 0 [foo3] => 0 ) after sorting: Array ( [foo] => 0 [foo1] => 0 [foo3] => 0 ) Array ( [0] => foo [1] => foo1 [2] => foo3 ) Array ( [0] => foo [1] => foo1 [2] => foo3 ) Array ( [0] => foo [1] => foo1 [2] => foo3 ) Array ( [0] => foo [1] => foo1 [2] => foo3 )
Output for 5.4.2 - 5.6.28
before sorting: Array ( [foo] => 0 [foo1] => 0 [foo3] => 0 ) after sorting: Array ( [foo3] => 0 [foo1] => 0 [foo] => 0 ) Array ( [0] => foo3 [1] => foo1 [2] => foo ) Array ( [0] => foo [1] => foo1 [2] => foo3 ) Array ( [0] => foo [1] => foo1 [2] => foo3 ) Array ( [0] => foo [1] => foo1 [2] => foo3 )
Output for 5.3.18 - 5.3.29
before sorting: Array ( [foo] => 0 [foo1] => 0 [foo3] => 0 ) after sorting: Array ( [foo3] => 0 [foo1] => 0 [foo] => 0 ) Array ( [0] => foo3 [1] => foo1 [2] => foo ) Array ( [0] => foo [1] => foo1 [2] => foo3 ) Array ( [0] => foo [1] => foo1 [2] => foo3 ) Notice: Use of undefined constant SORT_NATURAL - assumed 'SORT_NATURAL' in /in/WeFRT on line 26 Warning: sort() expects parameter 2 to be long, string given in /in/WeFRT on line 26 Array ( [0] => foo [1] => foo1 [2] => foo3 )