note 33946 added to function.array-diff-assoc
| From: | sc1n at yahoo dot com | Date: | Fri, 11 Jul 2003 17:10:10 +0000 |
| Subject: | note 33946 added to function.array-diff-assoc | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-51926@lists.php.net to get a copy of this message | ||
The following will recursively do an array_diff_assoc, which will calculate differences on a
multi-dimensional level. (Forgive me if the braces do not line up, the note script did not like my
tabs, and gave me trouble on some spaces.)
function array_diff_assoc_recursive($array1, $array2)
{
foreach($array1 as $key => $value)
{
if(is_array($value))
{
if(!is_array($array2[$key]))
{
$difference[$key] = $value;
}
else
{
$new_diff = array_diff_assoc_recursive($value, $array2[$key]);
if($new_diff != FALSE)
{
$difference[$key] = $new_diff;
}
}
}
elseif(!isset($array2[$key]) || $array2[$key] != $value)
{
$difference[$key] = $value;
}
}
return !isset($difference) ? 0 : $difference;
}
----
Manual Page -- http://www.php.net/manual/en/function.array-diff-assoc.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+33946
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+33946&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+33946&report=yes