我正在为我的论坛创建一个“固定”功能,我正在寻找一种方法将我的固定主题放在数组的开头,以便它们“卡在”页面的顶部.

如果主题没有固定,则topic_pinned = NULL,如果它被固定,则topic_pinned = 0.

该数组按topic_updated排序.固定主题需要在保留在页面顶部时按topic_updated保持排序,然后在固定主题下是非固定主题,也按topic_updated排序.

主题数组($forum_topic_results):

Array

(

[0] => Array

(

[topic_id] => 4

[topic_subject] => Test Subject #4

[topic_date] => 2015-09-10 18:34:18

[topic_by] => 1

[topic_pinned] =>

[topic_updated] => 2015-09-10 20:37:22

)

[1] => Array

(

[topic_id] => 3

[topic_subject] => Test Subject #3

[topic_date] => 2015-08-22 09:24:40

[topic_by] => 1

[topic_pinned] => 0

[topic_updated] => 2015-09-04 22:02:31

)

[2] => Array

(

[topic_id] => 2

[topic_subject] => Test Subject #2

[topic_date] => 2015-08-15 10:56:00

[topic_by] => 1

[topic_pinned] =>

[topic_updated] => 2015-09-04 19:45:32

)

[3] => Array

(

[topic_id] => 1

[topic_subject] => Test Subject #1

[topic_date] => 2015-08-30 19:48:17

[topic_by] => 1

[topic_pinned] => 0

[topic_updated] => 2015-09-03 00:44:38

)

)

PHP:

/**

* getAllTopics

*

* Retreives the topics of the chosen category from the `forum_topics` table.

*

* @param $cat_id

* @access public

*/

public function getAllTopics($cat_id=NULL)

{

$database=$this->database;

$database->query('SELECT topic_id, topic_subject, topic_date, topic_by, topic_pinned, topic_locked FROM forum_topics WHERE topic_cat = :catid ORDER BY topic_updated DESC', array(':catid' => $cat_id));

$result = $database->statement->fetchAll(PDO::FETCH_ASSOC);

return $result;

}

# Get topics

$forum_topic_results = $this->getAllTopics($_GET['cat']);

foreach($forum_topic_results as $forum_topic_row)

{

# Get user's username.

$topic_by=SearchUser($forum_topic_row['topic_by']);

$data.='

'.

'

'.

'

'.$forum_topic_row['topic_subject'].'

'.

'by '.$topic_by['username'].' on '.date('D M d, Y g:i a', strtotime($forum_topic_row['topic_date'])).

'

'.

'

';

}

结果我想:

Array

(

[0] => Array

(

[topic_id] => 3

[topic_subject] => Test Subject #3

[topic_date] => 2015-08-22 09:24:40

[topic_by] => 1

[topic_pinned] => 0

[topic_updated] => 2015-09-04 22:02:31

)

[1] => Array

(

[topic_id] => 1

[topic_subject] => Test Subject #1

[topic_date] => 2015-08-30 19:48:17

[topic_by] => 1

[topic_pinned] => 0

[topic_updated] => 2015-09-03 00:44:38

)

[2] => Array

(

[topic_id] => 4

[topic_subject] => Test Subject #4

[topic_date] => 2015-09-10 18:34:18

[topic_by] => 1

[topic_pinned] =>

[topic_updated] => 2015-09-10 20:37:22

)

[3] => Array

(

[topic_id] => 2

[topic_subject] => Test Subject #2

[topic_date] => 2015-08-15 10:56:00

[topic_by] => 1

[topic_pinned] =>

[topic_updated] => 2015-09-04 19:45:32

)

)

php 数组排序 按值,php – 按值排序数组相关推荐

  1. JavaScript 数组排序,随机排序,查找最大(最小)值,对象属性进行排序

    JavaScript 数组排序 1.数组排序- - -sort() 根据首字符进行排序,a-z.注意:会改变原数组 var array=["c","d",&qu ...

  2. 细说PHP笔记03(第7章)--数组与数据结构,数组定义,数组遍历,数组内部指针遍历,键值操作函数,统计数组函数,回调函数处理数组元素,数组排序,拆分、合并、分解、结合数组,数组实现堆栈,随机选取元素

    1.数组 索引数组:索引值是整数 关联数组:索引值是字符串 2.数组的定义 1.以直接赋值的方式声明 $数组名[下标]=资料内容 或 $数组名[关联字符串(键值)]=资料内容 <?php $va ...

  3. python 字典的值是列表_python实现求和python如何通过列表中字典的值对列表进行排序...

    一. 按字典值排序(默认为升序) x = {1:2, 3:4, 4:3, 2:1, 0:0} 1. sorted_x = sorted(x.iteritems(), key=operator.item ...

  4. Dist类系列(一):根据字典的key值、value值进行排序

    1.sorted()函数 sorted()函数签名:sorted(iterable, key=None, reverse=False) 参数 说明 iterable 任何可迭代对象,包括:列表.字典. ...

  5. python3.6字典有序_Python如何按值对字典进行排序?

    我有一个从数据库中的两个字段中读取值的字典:一个字符串字段和一个数字字段.字符串字段是唯一的,所以这是字典的关键. 我可以对键进行排序,但是如何根据这些值进行排序? 注意:我已阅读Stack Over ...

  6. 字典按照值或键进行排序

    字典按照值或键进行排序 使用sorted函数进行排序 sorted(iterable,key,reverse) sorted一共有iterable, key, reverse这三个参数; 参数 作用 ...

  7. python 对字典分别按照key值、value值进行排序

    1.sorted函数 首先介绍sorted函数,sorted(iterable,key,reverse),sorted一共有iterable,key,reverse这三个参数. 其中iterable表 ...

  8. PHP中 如何将二位数组按某一个或多个字段值(升序/降序)排序?数字索引被重置,关联索引保持不变...

    如何将二位数组按某一个或多个字段值(升序/降序)排序?数字索引被重置,关联索引保持不变 1.$arr=array( 2. array('id'=>1,'name'=>'will','age ...

  9. python字典按值(Values)排序的方法

    python字典按照值的大小来排序的方法 def set_rank(a_dict):a_sort_list = sorted(a_dict.items(),key=lambda x : x[1], r ...

  10. 剑指Offer值数字在排序数组中出现的次数

    题目描述 统计一个数字在排序数组中出现的次数. 解题思路 看到排序立马想到二分,利用STL的upper_bound与lower_bound处理即可.复杂度是O(log⁡N)O(\log N)O(log ...

最新文章

  1. 揭秘仿人机器人背后的技术秘密 | 优必选研究院技术专家刘益彰【附PPT】
  2. 继承、实现、依赖、关联、聚合、组合的联系与区别
  3. ubuntu搭配lamp
  4. 总结这阵子的FPGA工作
  5. 淘淘商城项目过程记录
  6. 字符串和数字之间的转化
  7. 哥谈的是语言,不是寂寞
  8. 【剑指offer】面试题03:数组中重复的数字(java)
  9. python - 获取时间戳(10位和13位)
  10. h5页面移动端的社会化分享_Adobe年尾续运H5页面
  11. ZOJ 3430 Detect the Virus
  12. 阈值分割--大津阈值法(OSTU)
  13. 收集常用汉字6725个
  14. 一个输入手机号获取验证码的页面,包含哪些测试流程?
  15. FileZilla 下载
  16. PHP从基础到高级详细教程(完整版)
  17. Thinkphp开发无需挂机开源版本支付系统原码带云端ZFB和WX免输入金额跳转支付
  18. Web课程设计——小米商城页面实战(html,css,js实现)
  19. OA项目(MVC项目)
  20. Qt Linguist(语言家)与QtCreator集成

热门文章

  1. OceanBase数据库实践入门——性能测试建议
  2. 5分钟了解阿里时序时空数据库
  3. 阿里云明确生态边界:不做SaaS、被集成
  4. Arthas实践--获取到Spring Context,然后为所欲为
  5. 最强NLP模型BERT可视化学习
  6. 网络数据隐私保护,阿里工程师怎么做?
  7. 飞天2.0 | 万物智能的基础服务
  8. TableStore发布多元索引功能,打造统一的在线数据平台
  9. 曦智科技发布最新光子计算处理器PACE
  10. 最新!MongoDB 重磅发布 MongoDB 5.0 和无服务器 Atlas