Created
June 6, 2012 08:09
-
-
Save ctrl-freak/2880578 to your computer and use it in GitHub Desktop.
Check Whether PHP Array is Indexed or Associative
This file contains hidden or 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
| <? // 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