I'm trying to rewrite two foreach
loops as for
loops so that I am able to stop them at 3. Here is the first and simple loop's original:
<?php foreach ($marketing[0]['values'] as $company) { ?>
<tr>
<td><?php echo $company['label']; ?></td>
<td><?php echo $company['value']; ?></td>
</tr>
<?php } ?>
Here is my attempted re-write:
<?php
for($i = 0; $i < 4; ++$i) {
$company = $marketing[0][$i]['values'];
?>
<tr>
<td><?php echo $company['label']; ?></td>
<td><?php echo $company['value']; ?></td>
</tr>
<?php } ?>
Here is the second and slightly more complicated foreach
loop that I haven't attempted yet.
<?php foreach ($sales as $sale) { ?>
<tr>
<td><?php echo $sale['key']; ?></td>
<td>
<?php
foreach ($sale['values'] as $values) {
if ($values['x'] == $currentTeam) {
echo $values['y'];
}
}
?>
</td>
</tr>
<?php } ?>