3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = [ 'blue' => 43, 'red' => 87, 'purple' => 130, 'green' => 12, 'yellow' => 31 ]; $bad_keys1 = [ 'purple', 'yellow', ]; $bad_keys2 = [ 'green', ]; function remove_blacklisted_keys(array $haystack, array ...$blacklists) { return array_diff_key($haystack, array_flip(array_merge(...$blacklists))); } function remove_blacklisted_keys_preflipped(array $haystack, array ...$blacklists) { return array_diff_key($haystack, ...$blacklists); } var_export(remove_blacklisted_keys($data, $bad_keys1)); echo "\n"; var_export(remove_blacklisted_keys($data, $bad_keys1, $bad_keys2)); echo "\n"; var_export(remove_blacklisted_keys_preflipped($data, array_flip($bad_keys1))); echo "\n"; var_export(remove_blacklisted_keys_preflipped($data, array_flip($bad_keys1), array_flip($bad_keys2)));
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
array ( 'blue' => 43, 'red' => 87, 'green' => 12, ) array ( 'blue' => 43, 'red' => 87, ) array ( 'blue' => 43, 'red' => 87, 'green' => 12, ) array ( 'blue' => 43, 'red' => 87, )

preferences:
85.26 ms | 1138 KiB | 4 Q