繁体   English   中英

Laravel刀片多维数组

[英]Laravel Blade Multidimensional Array

我有以下数组,我想在laravel刀片中将其作为HTML表

array:2 [▼
"chest" => array:2 [▼
"Chest Press" => array:1 [▼
  0 => "1"
]
"Flys" => array:2 [▼
  0 => "3"
  1 => "4"
]
]
"hints" => array:2 [▼
"Chest Press" => array:1 [▼
  0 => "test1"
]
"Flys" => array:1 [▼
  0 => "test2"
]
]
]

我尝试下面的方法,但是我没有正确的HTML表,前两列正确,但第三列不正确,关于如何在HTML表上打印的任何想法

  <table class="table table-striped table-hover table-reflow">
            <thead>
                <tr>
                  <th>Exercises</th>
                  <th>Days</th>
                  <th>Hints</th>


                </tr>
            </thead>
        <tbody>

        @foreach($chests['chest'] as $chest => $exc)
            <tr>
                <td>{{$chest}}</td>
                @foreach($exc as $key => $value)
                    <td>
                         <strong>{{$value}},</strong>
                    </td>
                @endforeach

        @endforeach

        @foreach($chests['hints'] as $hint => $hin)


                @foreach($hin as $key => $value)
                    <td>
                         <strong>{{$value}}</strong>
                    </td>

                @endforeach

              </tr>
        @endforeach

          </tbody>

回答

        <tbody>
          @foreach ($chests['chest'] as $exerciseName => $daysArray)
              <tr>
                  <td>{{ $exerciseName }}</td>
            @foreach ($daysArray as $day)

                  <td >{{  $day }}</td>
            @endforeach
                  <td>{{ $chests['hints'][$exerciseName][0] }}</td>
              </tr>
          @endforeach

          </tbody>

https://laracasts.com/discuss/channels/laravel/laravel-blade-multidimensional-array

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM