3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php // Everything is associative array in PHP. Ideal question to ask is if it is sequential // Secondly, going through entire list of items in array is unnecessary function isSequentialArray($array) { return !(bool)count(array_filter(array_keys($array), 'is_string')); } var_dump(isSequentialArray([])); // true/undefined var_dump(isSequentialArray(['a'])); // false var_dump(isAssoc([])); // undefined 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 1e2j0
Output for 7.0.0 - 7.2.0
bool(true) bool(true) Fatal error: Uncaught Error: Call to undefined function isAssoc() in /in/0aHns:13 Stack trace: #0 {main} thrown in /in/0aHns on line 13
Process exited with code 255.
Output for 5.4.9 - 5.6.28
bool(true) bool(true) Fatal error: Call to undefined function isAssoc() in /in/0aHns on line 13
Process exited with code 255.
Output for 5.3.19 - 5.3.29
Parse error: syntax error, unexpected '[', expecting ')' in /in/0aHns on line 11
Process exited with code 255.