3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $alternatives = array( 'foo' => 0, 'foo1' => 0, 'foo3' => 0, ); asort($alternatives, SORT_STRING); 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 mjj8q
Output for 7.0.0 - 7.2.0
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
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
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/rjbjk on line 21 Warning: sort() expects parameter 2 to be long, string given in /in/rjbjk on line 21 Array ( [0] => foo [1] => foo1 [2] => foo3 )