Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

screwtape_mk's avatar

looping multiping collections at the same time

I have seen this question asked a few times and in each case its not clear what the solution is.

I need to loop through 2 collections one contains employees info the other contains bookings of these employees

If something like this were possible

@foreach($Employees as $Employee, $bookings as $booking)
        // return something
@endforeach

Im reluctant to use a nested for loop if a nested for loop will mean the operation will first loop through the inner loop till done and repeats each time the outer loop increments

0 likes
1 reply
screwtape_mk's avatar

Ok what ended up working is to apply an if condition within the for loop to check if something like:

$Employee->id==$bookingRequests->first()->employee_id

Please or to participate in this conversation.