Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@eusonlito
Created September 23, 2021 09:45
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 eusonlito/bad44a672124b070679c67cf762ad040 to your computer and use it in GitHub Desktop.
Save eusonlito/bad44a672124b070679c67cf762ad040 to your computer and use it in GitHub Desktop.
PHP Array Whitelist and Blacklist functions
<?php
if (!function_exists('array_keys_whitelist')) {
function array_keys_whitelist(array $array, array $whitelist): array
{
return array_intersect_key($array, array_flip($whitelist));
}
}
if (!function_exists('array_keys_blacklist')) {
function array_keys_blacklist(array $array, array $blacklist): array
{
return array_diff_key($array, array_flip($blacklist));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment