1$collection = collect([1, 2, 3, 4]);
2
3$filtered = $collection->filter(function ($value, $key) {
4 return $value > 2;
5});
6
7$filtered->all();
8
9// [3, 4]
1public function index()
2{
3 $myStudents = [
4 ['id'=>1, 'name'=>'Hardik', 'mark' => 80],
5 ['id'=>2, 'name'=>'Paresh', 'mark' => 20],
6 ['id'=>3, 'name'=>'Akash', 'mark' => 34],
7 ['id'=>4, 'name'=>'Sagar', 'mark' => 45],
8 ];
9
10 $myStudents = collect($myStudents);
11
12 $passedstudents = $myStudents->filter(function ($value, $key) {
13 return data_get($value, 'mark') > 34;
14 });
15
16 $passedstudents = $passedstudents->all();
17
18 dd($passedstudents);
19}