3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function is_assoc($var) { return is_array($var) && array_diff_key($var,array_keys(array_keys($var))); } $a = [1, 2, 3, 4, 5]; $b = ['a', 'b', 'c']; $c = ['a' => 1, 'b' => 2, 'c' => 3]; $d = [0 => 1, 1 => 2, 2 => 3]; $e = [1 => 1, 2 => 2, 3 => 3]; $f = [0 => 1, 1 => 2, 2 => 3, 'a' => 4]; $g = 'foo'; $h = 123; var_dump(array_keys($a)); echo '$a '; var_dump(is_assoc($a)); echo '$b '; var_dump(is_assoc($b)); echo '$c '; var_dump(is_assoc($c)); echo '$d '; var_dump(is_assoc($d)); echo '$e '; var_dump(is_assoc($e)); echo '$f '; var_dump(is_assoc($f)); echo '$g '; var_dump(is_assoc($g)); echo '$h '; var_dump(is_assoc($h));
based on hkVSO
Output for 5.4.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
array(5) { [0]=> int(0) [1]=> int(1) [2]=> int(2) [3]=> int(3) [4]=> int(4) } $a bool(false) $b bool(false) $c bool(true) $d bool(false) $e bool(true) $f bool(true) $g bool(false) $h bool(false)
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/Ldlsb on line 7
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/Ldlsb on line 7
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/Ldlsb on line 7
Process exited with code 255.