Php 如何显示数组中的最后3个元素?
伙计们 我有密码:Php 如何显示数组中的最后3个元素?,php,Php,伙计们 我有密码: @foreach($receivedBills as $bill) <tr> <td>{{$bill->created}}</td> <td>{{"{$bill->date_from->format('d.m.Y')} - {$bill->date_to->format('d.m.Y')}"}}</td> <td>
@foreach($receivedBills as $bill)
<tr>
<td>{{$bill->created}}</td>
<td>{{"{$bill->date_from->format('d.m.Y')} - {$bill->date_to->format('d.m.Y')}"}}</td>
<td>{{$bill->cnt}}</td>
<td>{{$bill->amount}}</td>
<td>{{$bill->is_paid?'Оплачен':'Не оплачен'}}</td>
</tr>
@endforeach
@foreach($receivedBills as$bill)
{{$bill->created}
{{{$bill->date\u from->format('d.m.Y')}-{$bill->date\u to->format('d.m.Y')}
{{$bill->cnt}
{{$bill->amount}
{{$bill->是否已支付?'
@endforeach
它显示表中的所有数据。我想显示最后三个,我如何才能做到这一点?
我被提供了array\u slice($receivedbills,-3)
但是我不知道如何连接它为什么不更改sql查询添加一个order by并限制它@foreach(array_slice($receivedbills,-3)as$bill)但是还有@Baracuda078说的话……这是最简单的方法吗?如果你只需要最后三个,为什么要从数据库中检索它们?如果要显示最后3个查询,然后显示所有其余查询,则只能检索所有查询,而不是2个查询。