How to use break or continue with Laravel Eloquent Collection's each method. My code is this:
$objectives->each(function($objective) { Collection::make($objective)->each(function($action) { Collection::make($action)->each(function($success_indicator) { Collection::make($success_indicator)->each(function($success_indicator) { echo 'hi'; continue; }); }); }); });
We can return true/false true
for continue
, false
for break
Continue:
collect([1,2,3,4])->each(function ($item){ if ($item === 2) { return true; } echo $item; });
Output: 1 3 4
Break:
collect([1,2,3,4])->each(function ($item){ if ($item === 2) { return false; } echo $item; });
Output: 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With