tags:

views:

41

answers:

3

Hello,

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: */

?>
A: 

Check this out ;) http://uk2.php.net/function.array-reverse

if not, you could simply put every data on a new array (or wathever structure you are using) with the foreach http://php.net/manual/en/function.array-pop.php and then you have it in the other way ;) stack vs queue

Saikios
my php is encoded So cannot make any changes using reverse array..
MANnDAaR
My seccond option probably the best one for you then ;) first use one foreach and put the elements in a new structure following a LIFO then use a new foreach and just print it (or use it, or whatever :P) ;)
Saikios
+1  A: 

from=$replies|@array_reverse

ts
A: 

If your data is coming from a database simply use an ORDER BY clause instead of some hack in your template.

SELECT ... FROM ... ORDER BY date DESC
nikic