Php 如何在laravel刀片上设置for循环中的值 {{$last=date('Y')-120} {{$now=date('Y')} @对于($i={{$now}};$i

Php 如何在laravel刀片上设置for循环中的值 {{$last=date('Y')-120} {{$now=date('Y')} @对于($i={{$now}};$i,php,laravel,date,select,Php,Laravel,Date,Select,希望这会有所帮助 <select id="year" name="year" class="form-control "> {{ $last= date('Y')-120 }} {{ $now = date('Y') }} @for ($i ={{ $now }}; $i <= {{ $last }}; $i--) <option value="{{ $i }}">{{ $i }}</option>

希望这会有所帮助

<select id="year" name="year" class="form-control ">
    {{ $last= date('Y')-120 }}
    {{ $now = date('Y') }}

      @for ($i ={{ $now }}; $i <= {{ $last }}; $i--)
         <option value="{{ $i }}">{{ $i }}</option>
      @endfor               
</select>

{{--*/$last=date('Y')-120;/*--}
{{--*/$now=date('Y');/*-}
@对于($i=$now;$i将您的视图更改为:

<select id="year" name="year" class="form-control">
    {{-- */$last= date('Y')-120;/* --}}
    {{-- */$now = date('Y');/* --}}
    @for ($i = $now; $i <= $last; $i--)
    <option value="{{ $i }}">{{ $i }}</option>
    @endfor               
</select>


@对于($i=$now;$i基本上
{{$last=date('Y')-120}}
在这部分中,您显示的是值,但您需要分配值。因此,按如下方式分配:

<select id="year" name="year" class="form-control ">
    <?php $last= date('Y')-120; ?>
    <?php $now = date('Y'); ?>

    @for ($i = $now; $i <= $last; $i--)
        <option value="{{ $i }}">{{ $i }}</option>
    @endfor
</select>

for循环也是一样。只需比较值。不要将其放在blade语法中

<?php $last= date('Y')-120; ?>

{{$last=date('Y')-120}
{{$now=date('Y')}
@对于($i=$now;$i>=$last;$i--)
{{$i}
@结束
您可以编写

<select id="year" name="year" class="form-control ">
    {{ $last= date('Y')-120 }}
    {{ $now = date('Y') }}

    @for ($i = $now; $i >= $last; $i--)
        <option value="{{ $i }}">{{ $i }}</option>
    @endfor
</select>

{{$last=date('Y')-120}
{{$now=date('Y')}

@对于($i=$now;$i使用
@for($i=$now;$i最好的方法是使用
range()
foreach()

例如:

<div class="form-group">
  <label for="task" class="col-sm-1 control-label">Text</label>
     @for ($i = 0; $i < $count; $i++)
       <div class="col-sm-12">
           <input type="text" name="text[{{ $i }}]" id="text[{{ $i }}]" class="form-control">
      </div>
     @endfor
</div>
结果

@foreach(range(date('Y')-5, date('Y')) as $y)
    {{$y}}
@endforeach
文件:

  • range()

对于每个月的几天,您可以在laravel这样做

2014 2015 2016 2017 2018 2019 

白天
@foreach(范围(1,31)为$y)
{{$y}
@endforeach
在指定范围内的年份,比如说1951年到1951年,按降序排列,你可以这样做

<select class="form-control day-select">
   <option>Day</option>
      @foreach(range(1, 31) as $y)
        <option>{{$y}}</option>
      @endforeach
</select>

年
@foreach(范围(日期('Y')-16,日期('Y')-70)为$Y)
{{$y}
@endforeach

您可以使用以下代码

    @foreach ($data as $item)
        @foreach ($order_item->where('order_id',$item->id) as $i)
        @endforeach
    @endforeach

现在你可以像这样使用for循环

<?php $last= date('Y')-120; ?>

{{$last=date('Y')-120}
{{$now=date('Y')}
@对于($i=$now;$i>=$last;$i--)
{{$i}
@结束

有关更多信息:

请尝试此
@For($i=$now;$i在刀片模板中,
@
指令中的任何内容(例如
@For()
)都将被视为php,因此无需使用
{}
打印其值。
    @foreach ($data as $item)
        @foreach ($order_item->where('order_id',$item->id) as $i)
        @endforeach
    @endforeach
<?php $last= date('Y')-120; ?>
<select id="year" name="year" class="form-control ">
{{ $last= date('Y')-120 }}
{{ $now = date('Y') }}

@for ($i = $now; $i >= $last; $i--)
    <option value="{{ $i }}">{{ $i }}</option>
@endfor
</select>