3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function test($array) { try { return is_associative_array($array); } catch (Exception $e) { echo $e->getMessage(); return 'error'; } } function is_associative_array($array) { // your fav method here } // non-array - adjust according to your preferred error handling technique assert(test(null) === false); assert(test(false)); assert(test(new stdClass) === false); // empty array assert(test([]) === true); // numeric keys assert(test([null, 'a', 'b']) === false); // proper indexed array; also, to catch wrong isset usage assert(test([1 => 'a', 2 => 'b', 3 => 'c']) === true); // sequential but not 0-based assert(test([-1 => '', 0 => '', 1 => 'a']) === true); // sequential but not 0-based assert(test([0 => '', 2 => 'b', 3 => 'c']) === true); // 1 index missing assert(test([0 => '', 2 => 'b', 1 => 'a']) === true); // numeric but unordered assert(test([0 => '']) === false); // single item assert(test([1 => 'a']) === true); // single item assert(test([NAN]) === false); assert(test([NAN => '']) === true); assert(test([INF]) === false); assert(test([INF => '']) === true); // string keys assert(test(['' => '', 'a' => 'a', 'b' => 'b']) === true); // proper associative array assert(test(['' => '']) === true); // single item; also, associative even though '' == 0 // mixed keys assert(test(['' => '', 1 => 'a']) === true); // first key string but rest not assert(test(['' => '', 0 => '']) === true); // first key string but rest not assert(test([0 => '', 'a' => 'a']) === true); // first key numeric but rest not // numeric string keys assert(test([' 0' => '']) === true); // associative even though ' 0' == 0 assert(test(['00' => '']) === true); // associative even though '00' == 0 assert(test(['0*' => '']) === true); // associative even though '0*' == 0 assert(test(['0.0' => '']) === true); // associative even though '0.0' == 0.0 assert(test(['0x0' => '']) === true); // associative even though '0x0' == 0 assert(test(['0e0' => '']) === true); // associative even though '0e0' == 0
based on V3bcV
Output for 7.0.0 - 7.2.0
Warning: assert(): assert(test(null) === false) failed in /in/SZDsQ on line 22 Warning: assert(): assert(test(false)) failed in /in/SZDsQ on line 23 Warning: assert(): assert(test(new stdClass()) === false) failed in /in/SZDsQ on line 24 Warning: assert(): assert(test([]) === true) failed in /in/SZDsQ on line 27 Warning: assert(): assert(test([null, 'a', 'b']) === false) failed in /in/SZDsQ on line 30 Warning: assert(): assert(test([1 => 'a', 2 => 'b', 3 => 'c']) === true) failed in /in/SZDsQ on line 31 Warning: assert(): assert(test([-1 => '', 0 => '', 1 => 'a']) === true) failed in /in/SZDsQ on line 32 Warning: assert(): assert(test([0 => '', 2 => 'b', 3 => 'c']) === true) failed in /in/SZDsQ on line 33 Warning: assert(): assert(test([0 => '', 2 => 'b', 1 => 'a']) === true) failed in /in/SZDsQ on line 34 Warning: assert(): assert(test([0 => '']) === false) failed in /in/SZDsQ on line 35 Warning: assert(): assert(test([1 => 'a']) === true) failed in /in/SZDsQ on line 36 Warning: assert(): assert(test([NAN]) === false) failed in /in/SZDsQ on line 37 Warning: assert(): assert(test([NAN => '']) === true) failed in /in/SZDsQ on line 38 Warning: assert(): assert(test([INF]) === false) failed in /in/SZDsQ on line 39 Warning: assert(): assert(test([INF => '']) === true) failed in /in/SZDsQ on line 40 Warning: assert(): assert(test(['' => '', 'a' => 'a', 'b' => 'b']) === true) failed in /in/SZDsQ on line 43 Warning: assert(): assert(test(['' => '']) === true) failed in /in/SZDsQ on line 44 Warning: assert(): assert(test(['' => '', 1 => 'a']) === true) failed in /in/SZDsQ on line 47 Warning: assert(): assert(test(['' => '', 0 => '']) === true) failed in /in/SZDsQ on line 48 Warning: assert(): assert(test([0 => '', 'a' => 'a']) === true) failed in /in/SZDsQ on line 49 Warning: assert(): assert(test([' 0' => '']) === true) failed in /in/SZDsQ on line 52 Warning: assert(): assert(test(['00' => '']) === true) failed in /in/SZDsQ on line 53 Warning: assert(): assert(test(['0*' => '']) === true) failed in /in/SZDsQ on line 54 Warning: assert(): assert(test(['0.0' => '']) === true) failed in /in/SZDsQ on line 55 Warning: assert(): assert(test(['0x0' => '']) === true) failed in /in/SZDsQ on line 56 Warning: assert(): assert(test(['0e0' => '']) === true) failed in /in/SZDsQ on line 57
Output for 5.4.10 - 5.6.28
Warning: assert(): Assertion failed in /in/SZDsQ on line 22 Warning: assert(): Assertion failed in /in/SZDsQ on line 23 Warning: assert(): Assertion failed in /in/SZDsQ on line 24 Warning: assert(): Assertion failed in /in/SZDsQ on line 27 Warning: assert(): Assertion failed in /in/SZDsQ on line 30 Warning: assert(): Assertion failed in /in/SZDsQ on line 31 Warning: assert(): Assertion failed in /in/SZDsQ on line 32 Warning: assert(): Assertion failed in /in/SZDsQ on line 33 Warning: assert(): Assertion failed in /in/SZDsQ on line 34 Warning: assert(): Assertion failed in /in/SZDsQ on line 35 Warning: assert(): Assertion failed in /in/SZDsQ on line 36 Warning: assert(): Assertion failed in /in/SZDsQ on line 37 Warning: assert(): Assertion failed in /in/SZDsQ on line 38 Warning: assert(): Assertion failed in /in/SZDsQ on line 39 Warning: assert(): Assertion failed in /in/SZDsQ on line 40 Warning: assert(): Assertion failed in /in/SZDsQ on line 43 Warning: assert(): Assertion failed in /in/SZDsQ on line 44 Warning: assert(): Assertion failed in /in/SZDsQ on line 47 Warning: assert(): Assertion failed in /in/SZDsQ on line 48 Warning: assert(): Assertion failed in /in/SZDsQ on line 49 Warning: assert(): Assertion failed in /in/SZDsQ on line 52 Warning: assert(): Assertion failed in /in/SZDsQ on line 53 Warning: assert(): Assertion failed in /in/SZDsQ on line 54 Warning: assert(): Assertion failed in /in/SZDsQ on line 55 Warning: assert(): Assertion failed in /in/SZDsQ on line 56 Warning: assert(): Assertion failed in /in/SZDsQ on line 57
Output for 5.3.20 - 5.3.29
Parse error: syntax error, unexpected '[', expecting ')' in /in/SZDsQ on line 27
Process exited with code 255.