Sort list in reverse_array inside {foreach}

I use {foreach} inside smarty like this

{foreach key=num item=reply from=$replies}
//something goes here.
{/foreach}

I am currently receiving answers like ...

Old → Old → New → New

I want to arrange them in that order

New → New → Old → Old

How to do it?

thank

solvable

Thanks ts for this

from=$replies|@array_reverse

& Requires the 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: */

?>
+5
source share
3 answers

This will solve the problem:

from=$replies|@array_reverse
+26
source

Check out array_reverse();)

If not, you can just put the data in a new array (or whatever structure you use) with foreach and array_pop()then you have it differently;) stack vs queue

+2
source

, ORDER BY .

SELECT ... FROM ... ORDER BY date DESC
0

All Articles