3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php const REQUIRED = 1; const OPTIONAL = 2; const IS_ARRAY = 4; $args = [ 'a' => [IS_ARRAY], 'b' => [OPTIONAL], 'c' => [REQUIRED], 'd' => [REQUIRED] ]; uasort( $args, function ($a, $b) { if ($a[0] & IS_ARRAY === IS_ARRAY) { echo "a is array\n"; return -1; } if ($b[0] & IS_ARRAY === IS_ARRAY) { echo "b is array\n"; return 1; } if ($a[0] & OPTIONAL === OPTIONAL) { echo "a is optional\n"; return -1; } if ($b[0] & OPTIONAL === OPTIONAL) { echo "b is optional\n"; return 1; } return 0; } ); var_dump($args);
based on b3XjS
Output for hhvm-3.18.5 - 3.22.0, 7.1.0 - 7.3.0alpha1
b is array b is array b is array b is array a is array array(4) { ["c"]=> array(1) { [0]=> int(1) } ["d"]=> array(1) { [0]=> int(1) } ["a"]=> array(1) { [0]=> int(4) } ["b"]=> array(1) { [0]=> int(2) } }
Output for 5.6.0 - 5.6.30
a is array a is array a is array array(4) { ["d"]=> array(1) { [0]=> int(1) } ["c"]=> array(1) { [0]=> int(1) } ["b"]=> array(1) { [0]=> int(2) } ["a"]=> array(1) { [0]=> int(4) } }