Created
September 23, 2021 09:45
-
-
Save eusonlito/bad44a672124b070679c67cf762ad040 to your computer and use it in GitHub Desktop.
PHP Array Whitelist and Blacklist functions
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 | |
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