Let’s say we have the following two arrays
$firstArray=array(10,20,30,40,50); $secondArray=array(100,80,30,40,90);
We need to find the matching i.e. the output should be
30 40
Example
The PHP code is as follows
<!DOCTYPE html>
<html>
<body>
<?php
$firstArray=array(10,20,30,40,50);
$secondArray=array(100,80,30,40,90);
foreach($firstArray as $f){
foreach($secondArray as $s){
if($f==$s){
echo "The matching result is=",$f,"<br>";
}
}
}
?>
</body>
</html>Output
This will produce the following output
The matching result is=30 The matching result is=40