【问题标题】:populate table with headers using foreach loop in Laravel在 Laravel 中使用 foreach 循环使用标题填充表
【发布时间】:2022-11-11 14:54:56
【问题描述】:

我正在尝试使用 this table 之类的标题填充表格。 数组返回this type of data

我试过这个但不起作用。

@foreach ($players['headers'] as $row_header)
   <tr>
     @foreach ($players['values'] as $values)
        <th scope="row" class="col-3">{{ $row_header }}</th>
        <th class="col-3">{{ $values['values'][0] }}</th>
        <td class="col-3">{{ $values['values'][1] }}</td>
     @endforeach
   </tr>
 @endforeach

【问题讨论】:

    标签: php html laravel api


    【解决方案1】:

    在不知道您当前看到的错误或不准确结果的情况下,很难给您一个明确的答案。根据您提供的图像,我的建议是尝试这样的事情:

    @foreach ($players['headers'] as $key => $row_header)
       <tr>
         <th scope="row" class="col-3">{{ $row_header }}</th>
         @foreach ($players['values'] as $values)
           <td class="col-3">{{ $values['values'][$key] }}</td>
         @endforeach
       </tr>
     @endforeach
    

    对于 $players['values'] 的每个迭代,您不需要输出 $row_header,您只需输出一次。

    您的设置没有考虑您正在进行的 foreach 迭代,因此即使您想要输出其他值,您也总是输出“匹配”和“局”。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-12
      • 2016-05-03
      相关资源
      最近更新 更多