我有這個代碼我想始終從1開始,但它不工作,它繼續5 6 7 8等等。我想要的值= {{k}}
總是從1for循環不工作
<?php $k=1; ?>
@foreach($answers as $answer)
@if($answer->deleted == 0)
<div class="form-group {{ $errors->has('options.'.$k) ? ' has-error': '' }}"
id="option{{ $k}}">
<div class="checkbox col-xs-2 control-label" id="checkbox_control-label">
<label>
<input type="text" name="order[{{ $k }}]" value="{{$k}}" id="input_order">
</label>
</div>
<div class="col-xs-8">
<input type="text" name="options[{{ $k }}]" value="{{ $answer->text}}"
class="form-control">
<div class="col-xs-12"></div>
<span class="help-block">
<strong></strong>
</span>
</div>
<div class="col-xs-2">
<button type="button" value="{{ $k }}" class="btn btn-flat btn-default btn-sm"
id="delete_option" title="@lang('general.remove_option')">
<i class="fa fa-trash-o" aria-hidden="true"></i>
</button>
</div>
</div>
@endif
<?php $k++; ?>
@endforeach
在@ endif前移動增量變量'if'塊內部的變量'$ k ++' – Thamilan
$ K ++如果條件滿足 – Abid