I think this does what you are looking for.
Using your sample data, loop through the external arrays, then using array_diff_assoc for users each time. (Note that this assumes that when there is a difference, array_diff_assoc returns the value from the second passed array, which seems to do).
<?php $user1 = array("public" => 1, "private" => 1, "secret" => 1); $user2 = array("public" => 1, "private" =>1, "secret" => 1); $array1 = array ("user 1"=>$user1, "user 2"=>$user2); $user1 = array("public" => 1, "private" => 0, "secret" => 1); $user2 = array("public" => 1, "private" => 1, "secret" => 1); $array2 = array("user 1"=>$user1, "user 2"=>$user2); $results = array(); foreach ( $array1 as $user => $value ) { $diff = array_diff_assoc( $array1[$user], $array2[$user] ); if ($diff) { array_push($results,array($user=>$diff)); } } print_r($results); ?>
It returns:
Array ( [0] => Array ( [user 1] => Array ( [private] => 1 ) ) )
source share