3v4l.org

run code in 300+ PHP versions simultaneously
<?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
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Array ( [0] => a [1] => b [3] => d [4] => e ) Fatal error: Uncaught TypeError: array_keys(): Argument #1 ($array) must be of type array, string given in /in/tCIjk:5 Stack trace: #0 /in/tCIjk(5): array_keys('a') #1 /in/tCIjk(13): isIndexedArray('a') #2 {main} thrown in /in/tCIjk on line 5
Process exited with code 255.
Output for 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33
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.0.20, 7.1.0 - 7.1.20
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.5.24 - 5.5.35, 5.6.8 - 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.

preferences:
163.33 ms | 402 KiB | 183 Q