for循环,循环内进行递增
For loop, within a loop to carry on incrementing
我的当前视图设置如下:
用户需要完成每个问题的 6 个输入框。我需要每个输入框都有一个唯一的 ID。
当前循环:
@foreach($form as $question)
@foreach($question->questions as $question)
@for ($i = 1; $i < 7; $i++)
<input type="text" value="1" class="form-control"
name="{{ unique ID here }}">
@endfor
@endforeach
@endforeach
我无法使用$question
的id
字段,因为我需要第一个输入框以1
开头并递增。
因此,例如,在上面的设置中,它将遍历 7 个 $questions
,每个循环都有 6 个输入框。本质上,我希望它循环遍历第一个问题,递增到 6,循环遍历第二个问题,递增到 12 等等。
请问我怎样才能做到这一点?
也许不是最好的解决方案,但应该可行。
@foreach($form as $question)
@php $uniqueId=0; @endphp
@foreach($question->questions as $question)
@for ($i = 1; $i < 7; $i++)
@php $uniqueId++; @endphp
<input type="text" value="1" class="form-control"
name="{{ $uniqueId }}">
@endfor
@endforeach
@endforeach
我的当前视图设置如下:
用户需要完成每个问题的 6 个输入框。我需要每个输入框都有一个唯一的 ID。
当前循环:
@foreach($form as $question)
@foreach($question->questions as $question)
@for ($i = 1; $i < 7; $i++)
<input type="text" value="1" class="form-control"
name="{{ unique ID here }}">
@endfor
@endforeach
@endforeach
我无法使用$question
的id
字段,因为我需要第一个输入框以1
开头并递增。
因此,例如,在上面的设置中,它将遍历 7 个 $questions
,每个循环都有 6 个输入框。本质上,我希望它循环遍历第一个问题,递增到 6,循环遍历第二个问题,递增到 12 等等。
请问我怎样才能做到这一点?
也许不是最好的解决方案,但应该可行。
@foreach($form as $question)
@php $uniqueId=0; @endphp
@foreach($question->questions as $question)
@for ($i = 1; $i < 7; $i++)
@php $uniqueId++; @endphp
<input type="text" value="1" class="form-control"
name="{{ $uniqueId }}">
@endfor
@endforeach
@endforeach