I'm having problems to iterate twice on the same array:
<? $indice=0 ?>
<?php foreach ($comisiones as $comision1):?>
<tr>
<td><?php echo ++$indice ?></td>
<td><?php echo tag('select',array('name'=>'comision_'.$indice),true)?>
<?php foreach ($comisiones as $comision2):?>
<option value="<?php echo $comision2->getId()?>">
<?php echo $comision2->getNombre()." - ".$comision2->getDescripcion()?>
</option>
<?php endforeach?>
</select>
</td>
</tr>
<?php endforeach?>
The above code prints:
And I'm expecting to see something like this (labels of the combos in the images are not the same, but I think the idea is clear):
Thanks in advance
My first instict is don't use foreach
loops. I believe that PHP is using some internal pointers so the two foreach
loops affect each other's position. Instead use a normal for loop.
Based on your code it seems like you don't actually want a foreach loop in the outher loop. Just do a regular for loop from 0 to the size of the array. Something like this:
for ($i = 0; $i < count($comisiones); ++$i) {
// Do what you want
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With