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)); assert(test([]) === true); // empty array assert(test([null, 1, 2]) === true); // to catch wrong isset usage as in some answers assert(test(['' => '']) === false); // random test assert(test([0 => '']) === true); // random test assert(test([1 => 'a']) === false); // random test // numeric keys assert(test(['', 'a', 'b']) === true); // proper indexed array 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 // string keys assert(test(['' => '', 'a' => 'a', 'b' => 'b']) === false); // proper dictionary // 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 13kuU
Output for 7.0.0 - 7.2.0
Warning: assert(): assert(test([]) === true) failed in /in/DotMR on line 28 Warning: assert(): assert(test([null, 1, 2]) === true) failed in /in/DotMR on line 30 Warning: assert(): assert(test(['' => '']) === false) failed in /in/DotMR on line 31 Warning: assert(): assert(test([0 => '']) === true) failed in /in/DotMR on line 32 Warning: assert(): assert(test([1 => 'a']) === false) failed in /in/DotMR on line 33 Warning: assert(): assert(test(['', 'a', 'b']) === true) failed in /in/DotMR on line 36 Warning: assert(): assert(test([1 => 'a', 2 => 'b', 3 => 'c']) === false) failed in /in/DotMR on line 37 Warning: assert(): assert(test([-1 => '', 0 => '', 1 => 'a']) === false) failed in /in/DotMR on line 38 Warning: assert(): assert(test([0 => '', 2 => 'b', 3 => 'c']) === false) failed in /in/DotMR on line 39 Warning: assert(): assert(test([0 => '', 2 => 'b', 1 => 'a']) === false) failed in /in/DotMR on line 40 Warning: assert(): assert(test(['' => '', 'a' => 'a', 'b' => 'b']) === false) failed in /in/DotMR on line 43 Warning: assert(): assert(test(['' => '', 1 => 'a', 2 => 'b']) === false) failed in /in/DotMR on line 46 Warning: assert(): assert(test([0 => '', 1 => 'a', 'b' => 'b']) === false) failed in /in/DotMR on line 47 Warning: assert(): assert(test([' 0' => '']) === false) failed in /in/DotMR on line 50 Warning: assert(): assert(test(['00' => '']) === false) failed in /in/DotMR on line 51 Warning: assert(): assert(test(['0*' => '']) === false) failed in /in/DotMR on line 52 Warning: assert(): assert(test(['0.0' => '']) === false) failed in /in/DotMR on line 53 Warning: assert(): assert(test(['0x0' => '']) === false) failed in /in/DotMR on line 54 Warning: assert(): assert(test(['0e0' => '']) === false) failed in /in/DotMR on line 55
Output for 5.5.0 - 5.6.25
Warning: assert(): Assertion failed in /in/DotMR on line 28 Warning: assert(): Assertion failed in /in/DotMR on line 30 Warning: assert(): Assertion failed in /in/DotMR on line 31 Warning: assert(): Assertion failed in /in/DotMR on line 32 Warning: assert(): Assertion failed in /in/DotMR on line 33 Warning: assert(): Assertion failed in /in/DotMR on line 36 Warning: assert(): Assertion failed in /in/DotMR on line 37 Warning: assert(): Assertion failed in /in/DotMR on line 38 Warning: assert(): Assertion failed in /in/DotMR on line 39 Warning: assert(): Assertion failed in /in/DotMR on line 40 Warning: assert(): Assertion failed in /in/DotMR on line 43 Warning: assert(): Assertion failed in /in/DotMR on line 46 Warning: assert(): Assertion failed in /in/DotMR on line 47 Warning: assert(): Assertion failed in /in/DotMR on line 50 Warning: assert(): Assertion failed in /in/DotMR on line 51 Warning: assert(): Assertion failed in /in/DotMR on line 52 Warning: assert(): Assertion failed in /in/DotMR on line 53 Warning: assert(): Assertion failed in /in/DotMR on line 54 Warning: assert(): Assertion failed in /in/DotMR on line 55