In this example, i will show you laravel collection search. Step by step explain laravel eloquent collection search. i would like to share with you laravel collection search multidimensional array. Here you will learn laravel collection search example. So, let's follow few step to create example of collection search laravel.
Laravel Collection object provide several methods that will help to write your own logic. here we will learn how to use search method of laravel collection.
You can use collection search like as bellow syntax:
search()
search(function( 'You can write logic here' ))
Now we will see both examples bellow:
Example 1:
public function index()
{
$myArray = [34, 33, 36, 37];
$myArray = collect($myArray);
$result = $myArray->search(33);
dd($result);
}
Output:
1
Example 2:
public function index()
{
$myArray = [34, 33, 36, 37];
$myArray = collect($myArray);
$result = $myArray->search(function ($value, $key) {
return $value > 34;
});
dd($result);
}
Output:
2
I hope it can help you...
Do you like below Tutorials ?
- Angular Json Pipe Example | Json Pipe in Angular 9/8/7
- Angular Slice Pipe Example | Slice Pipe in Angular 9/8/7
- Angular Uppercase Pipe Example | Uppercase Pipe in Angular 9/8/7
- Angular LowerCase Pipe Example | LowerCase Pipe in Angular 9/8/7
- Angular Titlecase Pipe Example | Titlecase Pipe in Angular 9/8/7
- Angular KeyValue Pipe Example | KeyValue Pipe in Angular 9/8/7
- Call Method from One Component to Another Component in Angular
- Angular Push Object into Array Example