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)); //assert(test('')); //assert(test(0)); //assert(test(false)); //assert(test(new stdClass)); // 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 rRiAb
Output for 7.0.0 - 7.2.0
Warning: assert(): assert(test([]) === true) failed in /in/V3bcV on line 29 Warning: assert(): assert(test([null, 'a', 'b']) === false) failed in /in/V3bcV on line 32 Warning: assert(): assert(test([1 => 'a', 2 => 'b', 3 => 'c']) === true) failed in /in/V3bcV on line 33 Warning: assert(): assert(test([-1 => '', 0 => '', 1 => 'a']) === true) failed in /in/V3bcV on line 34 Warning: assert(): assert(test([0 => '', 2 => 'b', 3 => 'c']) === true) failed in /in/V3bcV on line 35 Warning: assert(): assert(test([0 => '', 2 => 'b', 1 => 'a']) === true) failed in /in/V3bcV on line 36 Warning: assert(): assert(test([0 => '']) === false) failed in /in/V3bcV on line 37 Warning: assert(): assert(test([1 => 'a']) === true) failed in /in/V3bcV on line 38 Warning: assert(): assert(test([NAN]) === false) failed in /in/V3bcV on line 39 Warning: assert(): assert(test([NAN => '']) === true) failed in /in/V3bcV on line 40 Warning: assert(): assert(test([INF]) === false) failed in /in/V3bcV on line 41 Warning: assert(): assert(test([INF => '']) === true) failed in /in/V3bcV on line 42 Warning: assert(): assert(test(['' => '', 'a' => 'a', 'b' => 'b']) === true) failed in /in/V3bcV on line 45 Warning: assert(): assert(test(['' => '']) === true) failed in /in/V3bcV on line 46 Warning: assert(): assert(test(['' => '', 1 => 'a']) === true) failed in /in/V3bcV on line 49 Warning: assert(): assert(test(['' => '', 0 => '']) === true) failed in /in/V3bcV on line 50 Warning: assert(): assert(test([0 => '', 'a' => 'a']) === true) failed in /in/V3bcV on line 51 Warning: assert(): assert(test([' 0' => '']) === true) failed in /in/V3bcV on line 54 Warning: assert(): assert(test(['00' => '']) === true) failed in /in/V3bcV on line 55 Warning: assert(): assert(test(['0*' => '']) === true) failed in /in/V3bcV on line 56 Warning: assert(): assert(test(['0.0' => '']) === true) failed in /in/V3bcV on line 57 Warning: assert(): assert(test(['0x0' => '']) === true) failed in /in/V3bcV on line 58 Warning: assert(): assert(test(['0e0' => '']) === true) failed in /in/V3bcV on line 59
Output for 5.4.9 - 5.6.28
Warning: assert(): Assertion failed in /in/V3bcV on line 29 Warning: assert(): Assertion failed in /in/V3bcV on line 32 Warning: assert(): Assertion failed in /in/V3bcV on line 33 Warning: assert(): Assertion failed in /in/V3bcV on line 34 Warning: assert(): Assertion failed in /in/V3bcV on line 35 Warning: assert(): Assertion failed in /in/V3bcV on line 36 Warning: assert(): Assertion failed in /in/V3bcV on line 37 Warning: assert(): Assertion failed in /in/V3bcV on line 38 Warning: assert(): Assertion failed in /in/V3bcV on line 39 Warning: assert(): Assertion failed in /in/V3bcV on line 40 Warning: assert(): Assertion failed in /in/V3bcV on line 41 Warning: assert(): Assertion failed in /in/V3bcV on line 42 Warning: assert(): Assertion failed in /in/V3bcV on line 45 Warning: assert(): Assertion failed in /in/V3bcV on line 46 Warning: assert(): Assertion failed in /in/V3bcV on line 49 Warning: assert(): Assertion failed in /in/V3bcV on line 50 Warning: assert(): Assertion failed in /in/V3bcV on line 51 Warning: assert(): Assertion failed in /in/V3bcV on line 54 Warning: assert(): Assertion failed in /in/V3bcV on line 55 Warning: assert(): Assertion failed in /in/V3bcV on line 56 Warning: assert(): Assertion failed in /in/V3bcV on line 57 Warning: assert(): Assertion failed in /in/V3bcV on line 58 Warning: assert(): Assertion failed in /in/V3bcV on line 59
Output for 5.3.19 - 5.3.29
Parse error: syntax error, unexpected '[', expecting ')' in /in/V3bcV on line 29
Process exited with code 255.