April 22, 2018 —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.
1public function has(2 $key3);
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// true10$collection->has('first');11 12// true13$collection->has('second');14 15// false16$collection->has('third');
∎
The following amazing people help support this site and my open source projects ♥️
If you're interesting in supporting my work and want to show up on this list, check out my GitHub Sponsors Profile.