Why not just check that the intersection is not empty? `$user_or_role = $user_or_role || !empty(array_intersect($user->roles, $xacml_roles));`, instead of the loop.