<?php
/**
* This diff algorithm works with arrays or normal values
* All elements in $one, not in $two are in diffed results
* Elements in $two that are not in $one are discluded
* @param mixed $one - to diff
* @param mixed $two - to compare
* @return see above
* If $one is array and $two is not, $one
* If $one is not array and $two is, $one
* If $one is not array and $two is not array and both match, NULL
*/
function recursive_diff_assoc($one, $two)
{
$diff = array();
if(is_array($one) && is_array($two))
{
foreach($one as $k1 => $v1)
{
if(!array_key_exists($k1, $two))
{
$diff[$k1] = $v1;
}
else
{
$pd = recursiveDiffAssoc($one[$k1], $two[$k1]);
if($pd != null)
{
$diff[$k1] = $pd;
}
}
}
}
else if(!is_array($one) || !is_array($two))
{
if($one != $two)
{
return $one;
}
else
{
return null;
}
}
return $diff;
}