Voting

: seven plus two?
(Example: nine)

The Note You're Voting On

francois-php at ceonizme dot fr
10 years ago
to chinello at gmail dot com
I've had to use your function but it showed that the use of isset can't differentiate the NULL values from not setted values.

Here's a version that takes care of this subtility.

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

Hope that helps
François

<< Back to user notes page

To Top