Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save paulhhowells/5396533 to your computer and use it in GitHub Desktop.
Save paulhhowells/5396533 to your computer and use it in GitHub Desktop.
array_numbered_key_elements() Many Drupal 7 arrays mix numeric and associate keys, and you often need to separate the numerically keyed children from the associatively keyed arrays. This function returns an array containing only the numbered keys ready to be iterated through.
/*
* returns: an array containing only the numbered keys
*
* notes: array_intersect_key() is faster than array_intersect()
*/
function array_numbered_key_elements($array) {
return array_intersect_key($array, element_children($array));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment