Organizational Research By

Surprising Reserch Topic

Question:how to calculate differences on a multi-dimensional level?



asked Sep 13, 2013 in PHP by ashish singh
edited Sep 12, 2013
0 votes
22 views



Related Hot Questions

1 Answer

0 votes

 

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; 
} 
?> 
answered Sep 13, 2013 by ashish singh
edited Sep 12, 2013

...