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')); } assert(isIndexedArray('a')); // false var_dump(isIndexedArray(NULL)); // 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 Gb7jO
Output for 7.2.0
Warning: array_keys() expects parameter 1 to be array, string given in /in/DZsPQ on line 5 Warning: array_filter() expects parameter 1 to be array, null given in /in/DZsPQ on line 5 Warning: count(): Parameter must be an array or an object that implements Countable in /in/DZsPQ on line 5 Warning: array_keys() expects parameter 1 to be array, null given in /in/DZsPQ on line 5 Warning: array_filter() expects parameter 1 to be array, null given in /in/DZsPQ on line 5 Warning: count(): Parameter must be an array or an object that implements Countable in /in/DZsPQ on line 5 bool(true) Fatal error: Uncaught Error: Call to undefined function isSequentialArray() in /in/DZsPQ:10 Stack trace: #0 {main} thrown in /in/DZsPQ on line 10
Process exited with code 255.
Output for 7.0.0 - 7.1.10
Warning: array_keys() expects parameter 1 to be array, string given in /in/DZsPQ on line 5 Warning: array_filter() expects parameter 1 to be array, null given in /in/DZsPQ on line 5 Warning: array_keys() expects parameter 1 to be array, null given in /in/DZsPQ on line 5 Warning: array_filter() expects parameter 1 to be array, null given in /in/DZsPQ on line 5 bool(true) Fatal error: Uncaught Error: Call to undefined function isSequentialArray() in /in/DZsPQ:10 Stack trace: #0 {main} thrown in /in/DZsPQ on line 10
Process exited with code 255.
Output for 5.5.0 - 5.6.28
Warning: array_keys() expects parameter 1 to be array, string given in /in/DZsPQ on line 5 Warning: array_filter() expects parameter 1 to be array, null given in /in/DZsPQ on line 5 Warning: array_keys() expects parameter 1 to be array, null given in /in/DZsPQ on line 5 Warning: array_filter() expects parameter 1 to be array, null given in /in/DZsPQ on line 5 bool(true) Fatal error: Call to undefined function isSequentialArray() in /in/DZsPQ on line 10
Process exited with code 255.