Simple collection filter

4 years ago

NoxxieNl

To show how the filter function works with a collection.

Code

$collect = collect([
  	[
      	'name' => 'all',
    ],
  	[
      	'name' => 'confiscation_vainly'
    ]
  ]);

$filterd = $collect->filter(function($cost) {
  	return $cost['name'] == 'all' || $cost['name'] == 'confiscation_vainly'; 
})->where('name', 'all');

$filterd->first();

Output

=> [
     "name" => "all",
   ]
New course: Desktop apps with Electron