0

次の配列があります。

$days = [
    ['dow' => 1, 'day' => 'Monday'],
    ['dow' => 2, 'day' => 'Tuesday'],
    ['dow' => 3, 'day' => 'Wednesday'],
    ['dow' => 4, 'day' => 'Thursday'],
    ['dow' => 5, 'day' => 'Friday'],
    ['dow' => 6, 'day' => 'Saturday'],
    ['dow' => 7, 'day' => 'Sunday'],
];

次のように、ブレードテンプレートでループしようとしています:

 @foreach ($days as $day)
       <label>{{$day['day']}}</label>
       {!! Form::text('day_of_wk[$day['dow']].start_time', null, ['class' => 'form-control'])!!}
  @endforeach

しかし、私はエラーが発生します:syntax error, unexpected 'dow' (T_STRING)

$day['dow']day_of_wk[] 入力配列に値を追加するにはどうすればよいですか?

4

1 に答える 1

6
  @foreach ($days as $day)
       <label>{{$day['day']}}</label>
       {!! Form::text('day_of_wk['.$day['dow'].'].start_time', null, ['class' => 'form-control'])!!}
  @endforeach

また

@foreach ($days as $day)
           <label>{{$day['day']}}</label>
           {!! Form::text("day_of_wk[{$day['dow']}].start_time", null, ['class' => 'form-control'])!!}
      @endforeach
于 2016-01-12T08:40:03.613 に答える