anarcat's array_intersect_key() implementation checks for key presence using isset() rather than array_key_exists(). Hence:
<?php
$a = array ('foo' => 'bar');
$b = array ('foo' => null);
var_dump(array_intersect_key($a, $b));
?>
returns an empty array (ie, no matching keys), which is probably not right. Also, the documented function signature takes two parameters, minimum, while anarcat's accepted one.
Consider this implementation instead:
<?php
function array_intersect_key() {
$numArgs = func_num_args();
if (2 <= $numArgs) {
$arrays =& func_get_args();
for ($idx = 0; $idx < $numArgs; $idx++) {
if (! is_array($arrays[$idx])) {
trigger_error('Parameter ' . ($idx+1) . ' is not an array', E_USER_ERROR);
return false;
}
}
foreach ($arrays[0] as $key => $val) {
for ($idx = 1; $idx < $numArgs; $idx++) {
if (! array_key_exists($key, $arrays[$idx])) {
unset($arrays[0][$key]);
}
}
}
return $arrays[0];
}
trigger_error('Not enough parameters; two arrays expected', E_USER_ERROR);
return false;
}
?>