📜  如何在 php 代码示例中反向获取 assoc

📅  最后修改于: 2022-03-11 14:54:07.125000             🧑  作者: Mango

代码示例1
while($row = mysql_fetch_assoc($result)){
    $items[] = $row;
}

$items = array_reverse($items ,true);

foreach($items as $item){
   echo $item['time']." - ".$item['username']." - ".$item['message'];
}

//another option can be

$query = mysql_query("SELECT * FROM (
                      SELECT time, username, message
                      FROM messages ORDER BY time 
                      DESC LIMIT 10) result 
                      ORDER BY time ASC   
                    ");