- var_dump: documentation ( source)
- array_filter: documentation ( source)
- extract: documentation ( source)
- in_array: documentation ( source)
<?php
function allowedArgs($input, $allowed) {
return array_filter(
$input,
function ($key) use ($allowed) {
return in_array($key, $allowed);
},
ARRAY_FILTER_USE_KEY
);
}
function example($args) {
extract(allowedArgs($args, ['foo', 'bar']));
var_dump($foo, $bar, $baz);
}
example(['bar' => 2, 'foo' => 1, 'baz'=> 3]);