L
L
lolrofl012020-01-05 19:23:13
Laravel
lolrofl01, 2020-01-05 19:23:13

Is there an analogue of array_search in laravel collections?

Good afternoon.
In collections, I found only the contains method, which returns true if the element was found in the collection or false if it was not found. And I need a method that, if an element is found, would return the key of this array. I leafed through the documentation on collections several times - but I didn’t find anything suitable, except perhaps .each, but this will have to be written a lot of extra if there is still an analogue of array_search.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
lolrofl01, 2020-01-05
@lolrofl01

I solved it using the ->where() method. In two-dimensional arrays, apparently, this is the only option. Although it’s quite convenient .. Thank you all)

P
part_os, 2020-01-05
@part_os

The search() method searches the collection for a given value and returns its key if the search is successful.....

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question