【发布时间】:2012-04-05 19:25:02
【问题描述】:
我目前在 PHP 中遇到问题,我想按创建日期对这些帖子进行排序,以便它们可以按降序显示。我一直在寻找一个 PHP 函数来做到这一点,但没有运气。
有没有简单的解决方案?任何想法将不胜感激:)
array
0 =>
array
'post_id' => string '1' (length=1)
'user_id' => string '3' (length=1)
'post' => string 'this is a post' (length=14)
'created' => string '2012-04-05 20:11:38' (length=19)
1 =>
array
'post_id' => string '2' (length=1)
'user_id' => string '2' (length=1)
'post' => string 'this is a post' (length=14)
'created' => string '2012-04-05 20:11:38' (length=19)
2 =>
array
'post_id' => string '3' (length=1)
'user_id' => string '5' (length=1)
'post' => string 'this is a post' (length=14)
'created' => string '2012-04-05 20:11:38' (length=19)
【问题讨论】:
-
这是来自数据库吗?如果没有,为什么不呢?
-
这个数组是从哪里加载的?
-
是的,看起来很像 MySQL 查询行。
ORDER BY created DESC -
它来自数据库,但因为我必须分别抓取每个用户的帖子,我试图将它组合起来......有没有更好的方法来做类似...... WHERE user_id = MySQL 中的数组(2,3,5)?
-
如果我们看不到您的查询,这很难说。
WHERE user_id IN (2,3,5)在 MySQL 中有效
标签: php arrays datetime sorting