Работа с циклом For
<?For ($i=1; $i<5; $i++){?>
<tr>
<th><input type="text" name="[$i][code]" value="" class="form-control" placeholder="Артикул"></th>
<th><input type="text" name="[$i?][name]" value="" class="form-control" placeholder="Наименование"></th>
<th><input type="text" name="[$i?][groups]" value="" class="form-control" placeholder="Группа товара"></th>
<th><input type="text" name="[$i?][unit]" value="" class="form-control" placeholder="Ед. измерения"></th>
</tr>
</div>
<? }?>
Здравствуйте. Подскажите как сделать, чтобы в name вставлялось значение $i. Т.е. чтобы получилось 4 блока input, в каждом блоке чтобы name был [1][code];...;[1][unit], а в следующем [2][code];...;[2].[unit]. Или у меня верно все?
Ответы (2 шт):
Автор решения: CbIPoK2513
→ Ссылка
<?for($i=1; $i<5; $i++){?>
<tr>
<th><input type="text" name="<?=[$i][code]?>" value="" class="form-control" placeholder="Артикул"></th>
<th><input type="text" name="<?=[$i][name]?>" value="" class="form-control" placeholder="Наименование"></th>
<th><input type="text" name="<?=[$i][groups]?>" value="" class="form-control" placeholder="Группа товара"></th>
<th><input type="text" name="<?=[$i][unit]?>" value="" class="form-control" placeholder="Ед. измерения"></th>
</tr>
</div> <!-- Это точно должно тут быть? -->
<? }?>