我有动态数据可以随时更改。例如:
这就是我现在所拥有的:
有时像这样:
|==============|======|====|====|
|List of people|John |June|Tom |
|Date Join |2017 |2018|2016|
|Hobby |soccer| |
|Remark | test test |
有时我会这样:
|==============|======|======|=====|
|List of people|John |June |Tom |
|Date Join |2017 |2018 |2016 |
|Hobby |soccer|tennis| |
|Remark | test test |
我想做这样的事情:(有什么办法吗?)
|==============|======|====|====|
|List of people|John |June|Tom |
|Date Join |2017 |2018|2016|
|Hobby | soccer |
|Remark | test test |
或者像这样:
|==============|======|====|====|
|List of people|John |June|Tom |
|Date Join |2017 |2018|2016|
|Hobby | soccer|Tennis |
|Remark | test test |
这是我使用的代码:(这是我为人员,日期和爱好列表的方式)
@foreach($object7 as $val)
<tr>
<th style="border: 1px black solid">List of people</th>
<?php
$test = $val->people;
$testa = rtrim($test, ', ');
$array = explode(', ', $testa);
$count4 = count($array);
?>
@foreach($array as $item)
@if(($val->people == NULL) || ( $count4 <= 1))
<td style="border: 1px black solid" colspan="8">
@else
<td style="border: 1px black solid" colspan="1">
@endif
{{$item}}
</td>
@endforeach
</tr>
@endforeach
编辑: 注释行只有1个值,而其余值可以有1个或更多值。我想要的是基于这一切,我怎样才能使它们全长相同?
答案 0 :(得分:1)
尝试&#34; colgroup&#34;标记让我们尝试设置它们的宽度以使其修复:
@foreach($object7 as $val)
<tr>
<td style="border: 1px black solid" with="40%">List of people</td>
<?php
$test = $val->people;
$testa = rtrim($test, ', ');
$array = explode(', ', $testa);
$count4 = count($array);
?>
@foreach($array as $item)
@if(($val->people == NULL) || ( $count4 <= 1))
<td style="border: 1px black solid" with="60%">
@else if($count4 == 2)
<td style="border: 1px black solid" with="40%">
@else
<td style="border: 1px black solid" with="20%">
@endif
{{$item}}
</td>
@endforeach
</tr>