note 36880 added to function.array-diff-assoc
| From: | Michael at rn2 dot php dot net | Date: | Sun, 26 Oct 2003 04:20:11 +0000 |
| Subject: | note 36880 added to function.array-diff-assoc | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-59294@lists.php.net to get a copy of this message | ||
As mentioned earlier, this function requires that both the key and the value match. To match (and
remove) based on keys only, try this function.
<?php
function array_diff_keys($source, $diff)
{
$res = $source;
foreach ($diff as $key=>$data) {
unset($res[$key]);
}
return $res;
}
// example
$a = array('a' => '1', 'b' => '2', 'c' =>
'3');
$b = array('a' => '2', 'b' => '2', 'e' =>
'4');
// Yields array('a' => '1', 'c' => '3')
// Note that the 'a' index is not removed (as one might expect)
$c = array_diff_assoc($a, $b);
// Yields array('c' => '3')
$d = array_diff_keys($a, $b);
?>
----
Manual Page -- http://www.php.net/manual/en/function.array-diff-assoc.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+36880
Delete -- http://master.php.net/manage/user-notes.php?action=delete+36880&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+36880&report=yes
Search -- http://master.php.net/manage/user-notes.php