I am using {foreach} within smarty like this
{foreach key=num item=reply from=$replies}
//something goes here.
{/foreach}
Currently I am getting replies arranged like...
Older --> Old --> New --> Newer
I want to arrange them in this order
Newer --> New --> Old --> Older
How to achieve this ?
Thanks
Solved
Thanks to ts for this
from=$replies|@array_reverse
& Required following smarty plugin
modifier.reverse_array.php
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty reverse_array modifier plugin
*
* Type: modifier<br>
* Name: reverse_array<br>
* Purpose: reverse arrays
* @author Noel McGran
* @param array
* @return array
*/
function smarty_modifier_reverse_array($array)
{
return array_reverse($array);
}
/* vim: set expandtab: */
?>
This will solve the problem:
from=$replies|@array_reverse
Check out array_reverse()
;)
if not, you could simply put data on a new array (or whatever structure you are using) with foreach and array_pop()
then you have it in the other way ;) stack vs queue
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With