1 2 3 4 5 6 7 8 9 10 11 12 | <?php $incomingData = [ 'allowed' => 23, 'alsoAllowed' => 42, 'notAllowed' => 'foo', ]; $allowedKeys = ['allowed', 'alsoAllowed']; $validIncoming = array_intersect_key($incomingData, array_flip($allowedKeys)); var_dump($validIncoming); |
array(2) { 'allowed' => int(23) 'alsoAllowed' => int(42) }