Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何显示数组中的最后3个元素?_Php - Fatal编程技术网

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个查询。