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_NAT); print_r($keys);
based on k6RgP
Output for 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 ) Warning: Use of undefined constant SORT_NAT - assumed 'SORT_NAT' (this will throw an Error in a future version of PHP) in /in/mjj8q on line 21 Warning: sort() expects parameter 2 to be integer, string given in /in/mjj8q on line 21 Array ( [0] => foo [1] => foo1 [2] => foo3 )
Output for 7.0.0 - 7.1.10
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 ) Notice: Use of undefined constant SORT_NAT - assumed 'SORT_NAT' in /in/mjj8q on line 21 Warning: sort() expects parameter 2 to be integer, string given in /in/mjj8q on line 21 Array ( [0] => foo [1] => foo1 [2] => foo3 )
Output for 5.3.18 - 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 ) Notice: Use of undefined constant SORT_NAT - assumed 'SORT_NAT' in /in/mjj8q on line 21 Warning: sort() expects parameter 2 to be long, string given in /in/mjj8q on line 21 Array ( [0] => foo [1] => foo1 [2] => foo3 )