Q:

Reverse PHP Array

Here is code code Im Working With:
<?php

function get_gold_time_noformat()

{
     $goldquery = mysql_query("SELECT * FROM ( 
    SELECT 
        @row := @row +1 AS rownum, time,metal
    FROM ( 
        SELECT @row :=0) r, metal_price 
    WHERE metal = 'GOLD' ORDER BY  `metal_price`.`time` DESC 
) ranked 
WHERE rownum % 16 = 1 
LIMIT 6
");

         while($result = mysql_fetch_array( $goldquery )) 
 { 

    echo "<div id=\"dates\">" . date('g a', strToTime($result['time'] . ' - 7 hours')) .  "</div>";   
 } 

         }
?>

I am simply trying to reverse the array, I tried using array_reverse but couldn't get it to work.

A:

Array reverse will work if you use it on an array.
<?php
function get_gold_time_noformat() {
    $goldquery = mysql_query("SELECT * FROM ( 
        SELECT 
            @row := @row +1 AS rownum, time,metal
        FROM ( 
            SELECT @row :=0) r, metal_price 
            WHERE metal = 'GOLD' ORDER BY  `metal_price`.`time` DESC 
        ) ranked 
        WHERE rownum % 16 = 1 
        LIMIT 6"
    );

    $array_result = array();

    while($result = mysql_fetch_array( $goldquery )) { 
        $array_result[] = $result;
    }

    $array_result = array_reverse( $array_result );

    foreach( $array_result as $result ) {
        echo "<div id=\"dates\">" . date('g a', strToTime($result['time'] . ' - 7 hours')) .  "</div>";   
    } 
}
?>

Although I suggest seeing if you can reverse it in the SQL.

