最近在学laravel,做一下学习笔记。

1、contains()方法判断集合是否包含给定的项目:

$collection = collect(['name' => 'Desk', 'price' => 100]);
var_dump($collection->contains('Desk'));// true
var_dump($collection->contains('New York'));// false

2、你也可以用 contains 方法匹配一对键/值,即判断给定的配对是否存在于集合中:


$collection = collect([
['product' => 'Desk', 'price' => 200],
['product' => 'Chair', 'price' => 100],
]);
var_dump($collection->contains('product', 'Bookcase'));// false

05-11 20:42