In some code I'm working on, I noticed that several variables are accessing it because of the outlines foreach.
This can be seen in the codeigniter view files of this particular application.
For example, a file of the form:
<?php
foreach ($items as $row):
endforeach;
<td>
<?php echo form_checkbox('option_1','1', FALSE); ?>
<?php echo form_hidden('weight_unit', $row->weight_unit); ?>
</td>
// etc...
This works (i.e. no errors), but I wonder if this will be considered bad practice, and if so, why? (scope, etc.)
Does anyone have an opinion about this, and should variables be called only inside their respective loops?
Another problem that I noticed is the need for a variable in several parts of the file of the form: should I refactor to have several cycles or should there be one foreach / endforeachand the beginning / end of the file.
Any suggestions are greatly appreciated. Thank.