nested foreach in PHP problem

Posted by Neuquino on Stack Overflow See other posts from Stack Overflow or by Neuquino
Published on 2010-03-28T14:34:10Z Indexed on 2010/03/28 14:43 UTC
Read the original article Hit count: 384

Filed under:
|

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:

code result

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):

expected results

Thanks in advance

© Stack Overflow or respective owner

Related posts about php

Related posts about foreach-loop