Organizational Research By

Surprising Reserch Topic

Question:how to check for missing keys in multidimensional array using php?



asked Sep 13, 2013 in PHP by rajesh
edited Sep 12, 2013
+1 vote
74 views



Related Hot Questions

1 Answer

0 votes

 

 
function n_array_diff_assoc ($a1, $a2, $assoc=true) {
    $r = array();
    if(is_array(current($a1))):
        foreach($a1 as $k => $v):
            if(isset($a2[$k])):
                $diff = n_array_diff($a1[$k], $a2[$k], $assoc);
                if (!empty($diff)):
                    $r[$k] = $diff;
                endif;
            else:
                $r[$k] = $v;
            endif;
        endforeach;
    else:
        $r = $assoc ? array_diff_assoc($a1, $a2) : array_diff_key($a1, $a2);
    endif;
    return $r;
}
?>
answered Sep 13, 2013 by rajesh
edited Sep 12, 2013

...