By John Koster
The has
method is used to determine if a item exists in the collection based on a given $key
. The has
method returns true
if the item exists and false
if it does not.
#Signature
1public function has(
2 $key
3);
#Example Use
The following example demonstrates the usage of the has
method:
1use Illuminate\Support\Collection;
2
3// Create a new collection instance.
4$collection = new Collection([
5 'first' => 'I am first',
6 'second' => 'I am second'
7]);
8
9// true
10$collection->has('first');
11
12// true
13$collection->has('second');
14
15// false
16$collection->has('third');
∎