Home > database >  Are there laravel method like in_array?
Are there laravel method like in_array?

Time:09-10

I try to use methods in https://laravel.com/docs/9.x/helpers instead of old php functions I used for many year. I did not find any laravel method like in_array.

I tried to use Str::contains , but failed it. Seems different ?

So any replacement of in_array ?

Thanks in advance!

CodePudding user response:

Using in_array seems perfectly acceptable and if it gets the job done for you and is not causing issues then stick with it.

That aside, there is the Arr::has() helper, or alternatively, you could convert your array to a collection and then use the contains() method, however that just uses in_array behind the scenes anyway.

  • Related