re: Which types of loops are most popular in the programming languages you use? VIEW POST


I always used to use foreach in php, but now I’ve swapped to using collection methods in Laravel as they are much more powerful and you can chain them together instead of having multiple loops or nested loops.

Here is an example of map, taken from the docs, which I use a lot

$collection = collect([1, 2, 3, 4, 5]);

$multiplied = $collection->map(function ($item, $key) {
    return $item * 2;


// [2, 4, 6, 8, 10]
code of conduct - report abuse