多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
php 两个数组取交集、并集、差集 交集:array_intersect() ``` $array1 = array(1, 2, 3, 4,); $array2 = array(4, 5, 6, 7, 8); $intersection = array_intersect($array1, $array2); ``` 并集:array_merge() ``` $array1 = array(1, 2, 3, 4,); $array2 = array(4, 5, 6, 7, 8); $merge = array_merge($array1, $array2); ``` 差集:array_diff() ``` $array1 = array(1, 2, 3, 4,); $array2 = array(4, 5, 6, 7, 8); $difference = array_diff($array1, $array2); ``` laravel 两个集合取交集、并集、差集 交集: 使用intersect()函数,用于获取两个集合的交集: ``` $collection1 = collect([1, 2, 3, 4, 5]); $collection2 = collect([4, 5, 6, 7, 8]); $intersection = $collection1->intersect($collection2); ``` 并集:使用union()函数,用于获取两个集合的并集: ``` $collection1 = collect([1, 2, 3, 4, 5]); $collection2 = collect([4, 5, 6, 7, 8]); $union = $collection1->union($collection2); ``` 差集:使用diff()函数,用于获取两个集合的差集: ``` $collection1 = collect([1, 2, 3, 4, 5]); $collection2 = collect([4, 5, 6, 7, 8]); $difference = $collection1->diff($collection2); ```