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')); } 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
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Fatal error: Uncaught TypeError: array_keys(): Argument #1 ($array) must be of type array, string given in /in/DZsPQ:5 Stack trace: #0 /in/DZsPQ(5): array_keys('a') #1 /in/DZsPQ(8): isIndexedArray('a') #2 {main} thrown in /in/DZsPQ on line 5
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Fatal error: Uncaught TypeError: array_keys(): Argument #1 ($array) must be of type array, string given in /in/DZsPQ:5 Stack trace: #0 /in/DZsPQ(5): array_keys('a') #1 /in/DZsPQ(8): isIndexedArray('a') #2 {main} thrown in /in/DZsPQ on line 5
Process exited with code 255.
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
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.0.33, 7.1.0 - 7.1.33
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.5.38, 5.6.0 - 5.6.40
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.

preferences:
266.11 ms | 402 KiB | 328 Q