Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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