Check if PHP array is associative

Technology CommunityCategory: PHPCheck if PHP array is associative
VietMX Staff asked 4 years ago

Consider:

function has_string_keys(array $array) {
  return count(array_filter(array_keys($array), 'is_string')) > 0;
}

If there is at least one string key, $array will be regarded as an associative array.