note 29808 modified in function.array-diff by vrana
| From: | vrana@php.net | Date: | Tue, 17 Aug 2004 13:57:34 +0000 |
| Subject: | note 29808 modified in function.array-diff by vrana | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-80021@lists.php.net to get a copy of this message | ||
<?php
function array_key_diff($ar1, $ar2) { // , $ar3, $ar4, ...
// returns copy of array $ar1 with those entries removed
// whose keys appear as keys in any of the other function args
$aSubtrahends = array_slice(func_get_args(),1);
foreach ($ar1 as $key => $val)
foreach ($aSubtrahends as $aSubtrahend)
if (array_key_exists($key, $aSubtrahend))
unset ($ar1[$key]);
return $ar1;
}
$a = array("c" => "catty", "b" => "batty",
"a" => "aunty", 5 => 4, 2.9 => 7, 11, "n" =>
"nutty");
$b = array(9, "d" => "ditty", "b" => "bratty",
"a" => null, 10, 13);
$c = array_key_diff ($a, $b, array(5 => 6));
?>
$c is then equivalent to array('c' => 'catty', 6 => 11, 'n'
=> 'nutty')
Csaba Gabor from New York
--was--
function array_key_diff($ar1, $ar2) { // , $ar3, $ar4, ...
// returns copy of array $ar1 with those entries removed
// whose keys appear as keys in any of the other function args
$aSubtrahends = array_slice(func_get_args(),1);
foreach ($ar1 as $key => $val)
foreach ($aSubtrahends as $aSubtrahend)
if (array_key_exists($key, $aSubtrahend))
unset ($ar1[$key]);
return $ar1;
}
$a = array("c" => "catty", "b" => "batty",
"a" => "aunty", 5 => 4, 2.9 => 7, 11, "n" =>
"nutty");
$b = array(9, "d" => "ditty", "b" => "bratty",
"a" => null, 10, 13);
$c = array_key_diff ($a, $b, array(5 => 6));
$c is then equivalent to array('c' => 'catty', 6 => 11, 'n'
=> 'nutty')
Csaba Gabor from New York
http://php.net/manual/en/function.array-diff.php