假设我们有以下两个数组
$firstArray=array(10,20,30,40,50); $secondArray=array(100,80,30,40,90);
我们需要找到匹配项,即输出应为
30 40
PHP代码如下
<!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>
输出结果
这将产生以下输出
The matching result is=30 The matching result is=40