note 98953 deleted from function.array-diff by danbrown
| From: | danbrown@php.net | Date: | Sat, 17 Jul 2010 18:00:34 +0000 |
| Subject: | note 98953 deleted from function.array-diff by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-170941@lists.php.net to get a copy of this message | ||
Note Submitter: dj dot bettega at gmail dot com
----
A small improvement on "thefrox at gmail dot com" function
This one preserves the key
function multidimensional_array_diff($a1,$a2)
{
$r = array();
foreach ($a2 as $key => $second)
{
foreach ($a1 as $key => $first)
{
if (isset($a2[$key]))
{
foreach ($first as $first_key => $first_value)
{
foreach ($second as $second_value)
{
if ($first_value == $second_value)
{
$true = true;
break;
}
}
if (!isset($true))
{
$r[$key][$first_key] = $first_value;
}
unset($true);
}
}
else
{
$r[$key] = $first;
}
}
}
return $r;
}