php - How to check for matching key value pairs -
i have sets of arrays key value pairs:
$array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4); $array2 = array('green' => 5, 'blue' => 1, 'yellow' => 7, 'cyan' => 8);
how check both arrays contain match key , value together? want place condition if $array1
, $array2
have matching pair blue=>1
something?
you can use array_intersect_assoc:
php > var_dump(count(array_intersect_assoc($array1,$array2)) > 0); bool(true) php > $array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4); php > $array2 = array('green' => 5, 'blue' => 2, 'yellow' => 7, 'cyan' => 8); php > var_dump(count(array_intersect_assoc($array1,$array2)) > 0); bool(false)
Comments
Post a Comment