Skip to content

Instantly share code, notes, and snippets.

@thomedes
Last active December 19, 2015 19:48
Show Gist options
  • Save thomedes/6008268 to your computer and use it in GitHub Desktop.
Save thomedes/6008268 to your computer and use it in GitHub Desktop.
php: Check if an array is associative or plain
<? 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);
}
@thomedes
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment