Created
September 7, 2018 12:52
-
-
Save lastguest/01d25b1d98c4537c3eaf958130d48cc0 to your computer and use it in GitHub Desktop.
[PHP] array_mask
This file contains hidden or 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 | |
function array_mask(array $unsafe, array $mask){ | |
return array_intersect_key(array_merge($mask, $unsafe), $mask); | |
} | |
$maschera_default = [ | |
'name' => 'Senza Nome', | |
'surname' => 'Senza Cognome', | |
'age' => 0, | |
]; | |
$data = [ | |
'surname' => 'Rossi', | |
'age' => 99, | |
'io_non_ci_devo_essere' => 123, | |
'io_neppure' => "blablabla" | |
]; | |
print_r( | |
array_mask($data, $maschera_default) | |
); | |
/* | |
Array | |
( | |
[name] => Senza Nome | |
[surname] => Rossi | |
[age] => 99 | |
) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment