Advertisement
vitozy

Laravel Collection - iteration

Apr 13th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.49 KB | None | 0 0
  1. $words = Collection::make(['apple', 'pear', 'melon', 'cherry']);
  2. foreach ($words as $word) {
  3.     echo $word . "<br>";
  4. }
  5.  
  6. $words->each(function ($word) {
  7.     echo $word . "<br>";
  8.     if ($word == 'melon') {
  9.         return false; //dinnyéig elég kiírni
  10.     }
  11. });
  12.  
  13. $students = Collection::make([['Géza', 15, '4/E'], ['Ferenc', 16, '5/A'], ['Gergő', 17, '6/C']]);
  14. $students->eachSpread(function ($name, $age, $class) {
  15.     echo "$name $age éves és a(z) $class osztályba jár.<br>";
  16. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement