Skip to content

Instantly share code, notes, and snippets.

@wpscholar
Created March 24, 2014 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wpscholar/9742794 to your computer and use it in GitHub Desktop.
Save wpscholar/9742794 to your computer and use it in GitHub Desktop.
Filter an array based on a white list of keys
<?php
/**
* Filter an array based on a white list of keys
*
* @param array $array
* @param array $keys
* @return array
*/
function array_keys_white_list( array $array, array $keys ) {
foreach ( $array as $key => $value ) {
if ( ! in_array( $key, $keys ) ) {
unset( $array[$key] );
}
}
return $array;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment