3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $arr = array(); $arr['i1']['val1'] = 99; $arr['i1']['val2'] = 100; $arr['i2']['val1'] = 89; $arr['i2']['val2'] = 101; function cmp($a, $b) { static $called = 0; echo $called++, "\n"; if ($called > 2) die('overflow'); if ($GLOBALS['arr'][$a]['val2'] > $GLOBALS['arr'][$b]['val2']) { return 1; } if ($GLOBALS['arr'][$q]['val2'] < $GLOBALS['arr'][$b]['val2']) { return -1; } return 0; } if (uksort($arr, 'cmp')) { echo "success\n"; } else { echo "failure\n"; } print_r($arr);
Output for 7.0.0 - 7.1.0
0 Notice: Undefined variable: q in /in/auZTO on line 17 Notice: Undefined index: in /in/auZTO on line 17 success Array ( [i1] => Array ( [val1] => 99 [val2] => 100 ) [i2] => Array ( [val1] => 89 [val2] => 101 ) )
Output for hhvm-3.10.0 - 3.12.0
0 Notice: Undefined index: in /in/auZTO on line 17 success Array ( [i1] => Array ( [val1] => 99 [val2] => 100 ) [i2] => Array ( [val1] => 89 [val2] => 101 ) )
Output for 4.3.0 - 5.6.28
0 success Array ( [i1] => Array ( [val1] => 99 [val2] => 100 ) [i2] => Array ( [val1] => 89 [val2] => 101 ) )