php如何比较两个数组

796
2021/3/19 17:35:17
栏目: 编程语言
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

php如何比较两个数组

在php中使用array_intersect()函数对两个数组进行比较,具体方法如下:

array_intersect()函数作用:

php中array_intersect()函数的作用是用于比较两个数组的元素,并返回其交集。

array_intersect()函数语法:

array_intersect(array1,array2);

参数:

array1,array2:需要进行比较的数组。

array_intersect()函数使用方法:

例:对$a1和$a2两个数组进行比较,并返回交集

$a1=array("e"=>"red","f"=>"black","g"=>"purple");

$a2=array("a"=>"red","b"=>"black","h"=>"yellow");

$result=array_intersect($a1,$a2);

print_r($result);

?>

辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读: PHP explode函数在处理长字符串时如何优化