Utilisez une variable externe dans la fonction PHP

//Make a new array $arr3 from $arr1 where keys of $arr1 is not in keys of $arr2
$arr = ['a' => 1, 'b' => 2, 'c' => 3];
$arr2 = ['a' => 5, 'b' => 6];

$arr3 = array_filter($arr, function ($k) use ($arr2) {
  return !in_array($k, array_keys($arr2));
}, ARRAY_FILTER_USE_KEY);
Foysal Remon