[英]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.