是否可以在 ID 之后对 foreach 循环的结果进行排序?首先是最高 ID,依此类推...因为它是文章,所以我希望最高 ID(最新)排在第一位 :)
我的代码:
include_once('includes/connection.php');
include_once('includes/article.php');
$article = new Article;
$articles = $article->fetch_all();
?>
<html>
<head>
<title>CMS</title>
<link rel="stylesheet" href="assets/style.css" />
</head>
<body>
<div class="container">
<a href="index.php" id="logo">CMS</a>
<ol>
<?php foreach ($articles as $article) { ?>
<li>
<a href="article.php?id=<?php echo $article['article_id']; ?>">
<?php echo $article['article_title']; ?>
</a>
- <small>
Posted <?php echo date('l jS', $article['article_timestamp']); ?>
</small>
</li>
<?php } ?>
</ol>
<br />
<small><a href="admin">Admin Login</a></small>
</div>
</body>
</html>