3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php // string, null, bool, float, largest specified previous index function isIndexedArray($array) { return !(bool)count(array_filter(array_keys($array), 'is_string')); } $a2 = array('a', 'b', 'c', 'd', 'e'); $a4 = $a2; unset($a4[2]); print_r($a4); var_dump(isIndexedArray('a')); // false var_dump(isSequentialArray([])); // true/undefined var_dump(isSequentialArray(['a'])); // true var_dump(isSequentialArray(['a' => 1])); // false var_dump(isSequentialArray(array(0 => 'a', 1 => 'b'))); // true var_dump(isSequentialArray(array(0 => 'a', 5 => 'b'))); // true var_dump(isSequentialArray(array('a', 'b', 'c'))); // false var_dump(isSequentialArray(array("0" => 'a', "1" => 'b', "2" => 'c'))); // false var_dump(isSequentialArray(array("1" => 'a', "0" => 'b', "2" => 'c'))); // true var_dump(isSequentialArray(array("a" => 'a', "b" => 'b', "c" => 'c'))); // true
based on LO1PD
Output for 7.2.0
Array ( [0] => a [1] => b [3] => d [4] => e ) Warning: array_keys() expects parameter 1 to be array, string given in /in/tCIjk on line 5 Warning: array_filter() expects parameter 1 to be array, null given in /in/tCIjk on line 5 Warning: count(): Parameter must be an array or an object that implements Countable in /in/tCIjk on line 5 bool(true) Fatal error: Uncaught Error: Call to undefined function isSequentialArray() in /in/tCIjk:14 Stack trace: #0 {main} thrown in /in/tCIjk on line 14
Process exited with code 255.
Output for 7.0.0 - 7.1.10
Array ( [0] => a [1] => b [3] => d [4] => e ) Warning: array_keys() expects parameter 1 to be array, string given in /in/tCIjk on line 5 Warning: array_filter() expects parameter 1 to be array, null given in /in/tCIjk on line 5 bool(true) Fatal error: Uncaught Error: Call to undefined function isSequentialArray() in /in/tCIjk:14 Stack trace: #0 {main} thrown in /in/tCIjk on line 14
Process exited with code 255.
Output for 5.4.9 - 5.6.28
Array ( [0] => a [1] => b [3] => d [4] => e ) Warning: array_keys() expects parameter 1 to be array, string given in /in/tCIjk on line 5 Warning: array_filter() expects parameter 1 to be array, null given in /in/tCIjk on line 5 bool(true) Fatal error: Call to undefined function isSequentialArray() in /in/tCIjk on line 14
Process exited with code 255.
Output for 5.3.19 - 5.3.29
Parse error: syntax error, unexpected '[', expecting ')' in /in/tCIjk on line 14
Process exited with code 255.