Skip to content

Instantly share code, notes, and snippets.

@ctrl-freak
Created June 6, 2012 08:09
Show Gist options
  • Select an option

  • Save ctrl-freak/2880578 to your computer and use it in GitHub Desktop.

Select an option

Save ctrl-freak/2880578 to your computer and use it in GitHub Desktop.
Check Whether PHP Array is Indexed or Associative
<? // http://stackoverflow.com/a/4254008/348146
function is_assoc($array) {
return (bool)count(array_filter(array_keys($array), 'is_string'));
}
// function assumes:
// 1. is_array($array) == true
// 2. if there is at least one string key, $array will be regarded as associative array
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment