php – Smarty reading last x numbers of rows of an array – Education Career Blog

I need to read for example last 3 items of an array in smarty.
Please advice.

,

Do this

 {assign var=lastRows value=$array|array_slice:-3}

And after this you may use $lastRows in any way you want.
You should also take a look at http://www.php.net/manual/en/function.array-slice.php

,

{foreach from=$array item=row name=foo}
{if $smarty.foreach.foo.index >= $smarty.foreach.foo.total - 3}
    {$row}
{/if}
{/foreach}

Leave a Comment