- 交集: 使用intersect()函數(shù),用于獲取兩個集合的交集:
$collection1 = collect([1, 2, 3, 4, 5]);
$collection2 = collect([4, 5, 6, 7, 8]);
$intersection = $collection1->intersect($collection2);
- 并集:使用union()函數(shù),用于獲取兩個集合的并集:
$collection1 = collect([1, 2, 3, 4, 5]);
$collection2 = collect([4, 5, 6, 7, 8]);
$union = $collection1->union($collection2);
- 差集:使用diff()函數(shù),用于獲取兩個集合的差集:
$collection1 = collect([1, 2, 3, 4, 5]);
$collection2 = collect([4, 5, 6, 7, 8]);
$difference = $collection1->diff($collection2);
文章來源地址http://www.zghlxwxcb.cn/news/detail-532655.html
文章來源:http://www.zghlxwxcb.cn/news/detail-532655.html
到了這里,關(guān)于laravel 兩個集合取交集、并集、差集的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!