Last active
December 19, 2015 19:48
-
-
Save thomedes/6008268 to your computer and use it in GitHub Desktop.
php: Check if an array is associative or plain
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? php | |
function is_assoc_array($a) { | |
return (is_array($a) | |
&& (array_keys($a) !== range(0, count($a) - 1))); | |
} | |
function is_plain_array($a) { | |
return is_array($a) && !is_assoc_array($a); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This works fine but it's obviously not very efficient. If you know a better way to do it please leave a reference to it.