3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function test($array) { try { return is_indexed_array($array); } catch (Exception $e) { echo $e->getMessage(); return 'error'; } } function is_indexed_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']) === true); // proper indexed array; also, to catch wrong isset usage assert(test([1 => 'a', 2 => 'b', 3 => 'c']) === false); // sequential but not 0-based assert(test([-1 => '', 0 => '', 1 => 'a']) === false); // sequential but not 0-based assert(test([0 => '', 2 => 'b', 3 => 'c']) === false); // 1 index missing assert(test([0 => '', 2 => 'b', 1 => 'a']) === false); // numeric but unordered assert(test([0 => '']) === true); // single item assert(test([1 => 'a']) === false); // single item assert(test([NAN]) === true); assert(test([NAN => '']) === false); assert(test([INF]) === true); assert(test([INF => '']) === false); // string keys assert(test(['' => '', 'a' => 'a', 'b' => 'b']) === false); // proper associative array assert(test(['' => '']) === false); // single item // mixed keys assert(test(['' => '', 1 => 'a', 2 => 'b']) === false); // first key string but rest not; also, associative even though '' == 0 assert(test([0 => '', 1 => 'a', 'b' => 'b']) === false); // first key numeric but rest not // numeric string keys assert(test([' 0' => '']) === false); // associative even though ' 0' == 0 assert(test(['00' => '']) === false); // associative even though '00' == 0 assert(test(['0*' => '']) === false); // associative even though '0*' == 0 assert(test(['0.0' => '']) === false); // associative even though '0.0' == 0.0 assert(test(['0x0' => '']) === false); // associative even though '0x0' == 0 assert(test(['0e0' => '']) === false); // associative even though '0e0' == 0
based on nl5WJ
Output for 7.0.0 - 7.2.0
Warning: assert(): assert(test([]) === true) failed in /in/ZRjU7 on line 29 Warning: assert(): assert(test([null, 'a', 'b']) === true) failed in /in/ZRjU7 on line 32 Warning: assert(): assert(test([1 => 'a', 2 => 'b', 3 => 'c']) === false) failed in /in/ZRjU7 on line 33 Warning: assert(): assert(test([-1 => '', 0 => '', 1 => 'a']) === false) failed in /in/ZRjU7 on line 34 Warning: assert(): assert(test([0 => '', 2 => 'b', 3 => 'c']) === false) failed in /in/ZRjU7 on line 35 Warning: assert(): assert(test([0 => '', 2 => 'b', 1 => 'a']) === false) failed in /in/ZRjU7 on line 36 Warning: assert(): assert(test([0 => '']) === true) failed in /in/ZRjU7 on line 37 Warning: assert(): assert(test([1 => 'a']) === false) failed in /in/ZRjU7 on line 38 Warning: assert(): assert(test([NAN]) === true) failed in /in/ZRjU7 on line 39 Warning: assert(): assert(test([NAN => '']) === false) failed in /in/ZRjU7 on line 40 Warning: assert(): assert(test([INF]) === true) failed in /in/ZRjU7 on line 41 Warning: assert(): assert(test([INF => '']) === false) failed in /in/ZRjU7 on line 42 Warning: assert(): assert(test(['' => '', 'a' => 'a', 'b' => 'b']) === false) failed in /in/ZRjU7 on line 45 Warning: assert(): assert(test(['' => '']) === false) failed in /in/ZRjU7 on line 46 Warning: assert(): assert(test(['' => '', 1 => 'a', 2 => 'b']) === false) failed in /in/ZRjU7 on line 49 Warning: assert(): assert(test([0 => '', 1 => 'a', 'b' => 'b']) === false) failed in /in/ZRjU7 on line 50 Warning: assert(): assert(test([' 0' => '']) === false) failed in /in/ZRjU7 on line 53 Warning: assert(): assert(test(['00' => '']) === false) failed in /in/ZRjU7 on line 54 Warning: assert(): assert(test(['0*' => '']) === false) failed in /in/ZRjU7 on line 55 Warning: assert(): assert(test(['0.0' => '']) === false) failed in /in/ZRjU7 on line 56 Warning: assert(): assert(test(['0x0' => '']) === false) failed in /in/ZRjU7 on line 57 Warning: assert(): assert(test(['0e0' => '']) === false) failed in /in/ZRjU7 on line 58
Output for 5.4.9 - 5.6.28
Warning: assert(): Assertion failed in /in/ZRjU7 on line 29 Warning: assert(): Assertion failed in /in/ZRjU7 on line 32 Warning: assert(): Assertion failed in /in/ZRjU7 on line 33 Warning: assert(): Assertion failed in /in/ZRjU7 on line 34 Warning: assert(): Assertion failed in /in/ZRjU7 on line 35 Warning: assert(): Assertion failed in /in/ZRjU7 on line 36 Warning: assert(): Assertion failed in /in/ZRjU7 on line 37 Warning: assert(): Assertion failed in /in/ZRjU7 on line 38 Warning: assert(): Assertion failed in /in/ZRjU7 on line 39 Warning: assert(): Assertion failed in /in/ZRjU7 on line 40 Warning: assert(): Assertion failed in /in/ZRjU7 on line 41 Warning: assert(): Assertion failed in /in/ZRjU7 on line 42 Warning: assert(): Assertion failed in /in/ZRjU7 on line 45 Warning: assert(): Assertion failed in /in/ZRjU7 on line 46 Warning: assert(): Assertion failed in /in/ZRjU7 on line 49 Warning: assert(): Assertion failed in /in/ZRjU7 on line 50 Warning: assert(): Assertion failed in /in/ZRjU7 on line 53 Warning: assert(): Assertion failed in /in/ZRjU7 on line 54 Warning: assert(): Assertion failed in /in/ZRjU7 on line 55 Warning: assert(): Assertion failed in /in/ZRjU7 on line 56 Warning: assert(): Assertion failed in /in/ZRjU7 on line 57 Warning: assert(): Assertion failed in /in/ZRjU7 on line 58
Output for 5.3.19 - 5.3.29
Parse error: syntax error, unexpected '[', expecting ')' in /in/ZRjU7 on line 29
Process exited with code 255.