Created
March 24, 2014 15:41
-
-
Save wpscholar/9742794 to your computer and use it in GitHub Desktop.
Filter an array based on a white list of keys
This file contains 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
<?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