3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function test(array $array) { try { return isDictionary($array); } catch (Exception $e) { echo 'ss'; return 'error'; } } function isDictionary($array) { foreach($array as $key => $value) { return ! is_int($key); } return false; } assert(isDictionary(['', 'a', 'b'])); assert(isDictionary([1 => 'a', 2 => 'b', 3 => 'c'])); assert(isDictionary([0 => '', 2 => 'b'])); assert(isDictionary([0 => '', 2 => 'b', 1 => 'a'])); assert(isDictionary([0 => '', 3 => 'c', 2 => 'b'])); assert(isDictionary([0 => '', null => '', 2 => 'b'])); assert(isDictionary([null => '', 1 => 'a', 2 => 'b']));
based on D6EFQ
Output for 7.0.0 - 7.2.0
Warning: assert(): assert(isDictionary(['', 'a', 'b'])) failed in /in/nfPn3 on line 23 Warning: assert(): assert(isDictionary([1 => 'a', 2 => 'b', 3 => 'c'])) failed in /in/nfPn3 on line 24 Warning: assert(): assert(isDictionary([0 => '', 2 => 'b'])) failed in /in/nfPn3 on line 25 Warning: assert(): assert(isDictionary([0 => '', 2 => 'b', 1 => 'a'])) failed in /in/nfPn3 on line 26 Warning: assert(): assert(isDictionary([0 => '', 3 => 'c', 2 => 'b'])) failed in /in/nfPn3 on line 27 Warning: assert(): assert(isDictionary([0 => '', null => '', 2 => 'b'])) failed in /in/nfPn3 on line 28
Output for 5.4.9 - 5.6.28
Warning: assert(): Assertion failed in /in/nfPn3 on line 23 Warning: assert(): Assertion failed in /in/nfPn3 on line 24 Warning: assert(): Assertion failed in /in/nfPn3 on line 25 Warning: assert(): Assertion failed in /in/nfPn3 on line 26 Warning: assert(): Assertion failed in /in/nfPn3 on line 27 Warning: assert(): Assertion failed in /in/nfPn3 on line 28
Output for 5.3.19 - 5.3.29
Parse error: syntax error, unexpected '[', expecting ')' in /in/nfPn3 on line 23
Process exited with code 255.