如何传递数组值以在 table 视图 laravel 中显示

How to pass array value to show in table views laravel

我正在尝试使 table 视图具有来自我控制器中数组的值。

这是我的控制器:

public function Loan Data(Request $request)
{
  $a = array("1", "2", "3", "4", "5");
  $b = array("110", "120", "130", "140", "150");
  $c = array("200", "220", "230", "240", "250");

  $array_all = ['bunga'=>$a,'pokok'=>$b,'pinjaman'=>$c,];
return view('show',[
        'all' => $array_all
    ]);
}

如何将数组传递给具有 table 的视图

<table>
<tr>
    <th>Data 1</th>
    <th>Data 2</th>
    <th>Data 3</th>
</tr>
<tr>
    <td>Value of array a here</td>
    <td> value of array b here</td>
    <td> value of array c here</td>
</tr>
</table>

如果我没理解错的话,你想要这样的东西:


<table>
    <tr>
        <th>Row Title</th>
        
        <th>Data 1</th>
        <th>Data 2</th>
        <th>Data 3</th>
    </tr>
    @foreach ($all as $rowTitle => $row)
    <tr>
        <td>{{ $rowTitle }}</td>
        
        @foreach ($row as $col)
             <td>{{ $col }}</td>
        @endforeach
    </tr>
    @endforeach
</table>

如果你想让数据沿对角线旋转,那么试试这样:

<table>
    <tr>
        <th>Data 1</th>
        <th>Data 2</th>
        <th>Data 3</th>
    </tr>
    @foreach ($all['bunga'] as $index => $value)
    <tr>
        <td>{{ $all['bunga'][$index] }}</td>
        <td>{{ $all['pokok'][$index] }}</td>
        <td>{{ $all['pinjaman'][$index] }}</td>
    </tr>
    @endforeach
</table>