php array_intersect is to find the intersection of two arrays

<!DOCTYPE html>
<html>
<body>
<?php
$a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");
$a2=array("e"=>"red","f"=>"green","g"=>"blue");
$result=array_intersect($a1,$a2);
print_r($result);
?>
</body>
</html>
Array ( [a] => red [b] => green [c] => blue )
////////////////////////////////////////////////////////////////////////
<!DOCTYPE html>
<html>
<body>
<?php
$a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");
$a2=array("e"=>"red","f"=>"black","g"=>"purple");
$a3=array("a"=>"red","b"=>"black","h"=>"yellow");
$result=array_intersect($a1,$a2,$a3);
print_r($result);
?>
</body>
</html>
Array ( [a] => red )

Leave a Reply

Your email address will not be published.

en_USEnglish