note 38344 modified in function.array-diff-assoc by aidan
| From: | aidan@php.net | Date: | Tue, 08 Jun 2004 14:20:02 +0000 |
| Subject: | note 38344 modified in function.array-diff-assoc by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-70461@lists.php.net to get a copy of this message | ||
here is a slightly enhanced version of Micheal Johnsons function (posted 26.oct.2003), this version
accepts arguments in the same way as array_diff_assoc (i.e. you can pass as many arrays as you want
- any arguments that are not arrays are ignored). If the first argument is not an array you
automatically get empty array back:
<?
function array_diff_assoc()
{
$args = func_get_args();
$res = $args[0];
if(!is_array($res)) {
return array();
}
for($i=1;$i<count($args);$i++) {
if(!is_array($args[$i])) {
continue;
}
foreach ($args[$i] as $key => $data) {
unset($res[$key]);
}
}
return $res;
}
?>
--was--
here is a slightly enhanced version of Micheal Johnsons function (posted 26.oct.2003), this version
accepts arguments in the same way as array_diff_assoc (i.e. you can pass as many arrays as you want
- any arguments that are not arrays are ignored). If the first argument is not an array you
automatically get empty array back:
<?
function array_diff_keys()
{
$args = func_get_args();
$res = $args[0];
if(!is_array($res)) {
return array();
}
for($i=1;$i<count($args);$i++) {
if(!is_array($args[$i])) {
continue;
}
foreach ($args[$i] as $key => $data) {
unset($res[$key]);
}
}
return $res;
}
?>
http://www.php.net/manual/en/function.array-diff-assoc.php