Voting

: max(five, three)?
(Example: nine)

The Note You're Voting On

chinello at gmail dot com
18 years ago
The following will recursively do an array_diff_assoc, which will calculate differences on a multi-dimensional level. This not display any notices if a key don't exist and if error_reporting is set to E_ALL:

<?php
function array_diff_assoc_recursive($array1, $array2)
{
foreach(
$array1 as $key => $value)
{
if(
is_array($value))
{
if(!isset(
$array2[$key]))
{
$difference[$key] = $value;
}
elseif(!
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;
}
?>

[NOTE BY danbrown AT php DOT net: This is a combination of efforts from previous notes deleted. Contributors included (Michael Johnson), (jochem AT iamjochem DAWT com), (sc1n AT yahoo DOT com), and (anders DOT carlsson AT mds DOT mdh DOT se).]

<< Back to user notes page

To Top