This is rather confusing but just go with me here. I have an array of 32 objects which I would like to loop through and display in a table. I can iterate through the array like this (using blade):
<table class="table table-bordered">
<thead>
@foreach($stats as $stat)
@foreach($stat as $property => $value)
<th>
{{ $property }}
</th>
@endforeach
@endforeach
</thead>
<tbody>
@foreach($stats as $stat)
<tr>
@foreach($stat as $property => $value)
<td>
{{ $value }}
</td>
@endforeach
</tr>
@endforeach
</tbody>
</table>
and this performs the loops... well? What happens is the table body is populated correctly and the table head also is populated however, the properties in the table head repeat for each of the 32 objects. So it's a really long table head!
Let me clear up why I'm double looping... $stats
is an array full of 32 objects that I paginate over using Laravel. So I loop through that then I need to loop through the individual object to add it's property in the head and it's value in the body. Which is why I also nest a loop in the head and the body. One for property and one for value.