DEV Community

loading...
Cover image for Laravel Collection difference between contains() & containsStrict() Methods

Laravel Collection difference between contains() & containsStrict() Methods

larainfo
Full Stack Developer | Laravel | Livewire | Vue Js Nodejs, tailwind css
Originally published at larainfo.com ・1 min read

In this post, we will see about difference between contains() & containsStrict() Methods

contains() Method #

if we Look contains() method Syntax:

/**
     * Determine if an item exists in the enumerable.
     *
     * @param  mixed  $key
     * @param  mixed  $operator
     * @param  mixed  $value
     * @return bool
     */
    public function contains($key, $operator = null, $value = null);
Enter fullscreen mode Exit fullscreen mode

contains() if an element exists in the collection matching a given truth other wise it return false .let see example

$collection = collect([
        'apple',
        'samsung',
        'xiaomi',
        'oppo'
    ]);
$collection->contains('apple'); //true

$collection->contains('htc'); //false

Enter fullscreen mode Exit fullscreen mode

we can see apple is exists then it will return true and htc not exists then it will return false

Problem with contains() method #

Read more...

Read also #

Laravel php artisan inspire command
Laravel clear cache without using artisan command

Discussion (0)