Skip to content

Instantly share code, notes, and snippets.

@stemar
Last active December 7, 2019 00:06
Show Gist options
  • Save stemar/5190634 to your computer and use it in GitHub Desktop.
Save stemar/5190634 to your computer and use it in GitHub Desktop.
Select a subset of an associative array by providing the keys.
<?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