3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function isAssoc($array) { return !(bool)count(array_filter(array_keys($array), 'is_string')); } // everything is associative array in PHP. Ideal question to ask is if it sequential var_dump(isAssoc(array())); // true/undefined var_dump(isAssoc(['a'])); // false var_dump(isAssoc([])); // undefined var_dump(isAssoc(array(0 => 'a', 1 => 'b'))); // true var_dump(isAssoc(array(0 => 'a', 5 => 'b'))); // true var_dump(isAssoc(array('a', 'b', 'c'))); // false var_dump(isAssoc(array("0" => 'a', "1" => 'b', "2" => 'c'))); // false var_dump(isAssoc(array("1" => 'a', "0" => 'b', "2" => 'c'))); // true var_dump(isAssoc(array("a" => 'a', "b" => 'b', "c" => 'c'))); // true
based on FGoNc
Output for 5.4.9 - 7.3.0rc4
bool(true) bool(true) bool(true) bool(true) bool(true) bool(true) bool(true) bool(true) bool(false)
Output for 5.3.19 - 5.3.29
Parse error: syntax error, unexpected '[', expecting ')' in /in/1e2j0 on line 9
Process exited with code 255.