Last active
December 7, 2019 00:06
-
-
Save stemar/5190634 to your computer and use it in GitHub Desktop.
Select a subset of an associative array by providing the 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 | |
/** | |
* Select a subset of an associative array by providing the keys. | |
* | |
* @param array $assoc | |
* @param array $keys | |
* @return array | |
*/ | |
function array_select(array $assoc, array $keys) { | |
return array_intersect_key($assoc, array_flip($keys)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment