日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

php 数组排序 按值,php – 按值排序数组

發布時間:2024/9/27 php 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php 数组排序 按值,php – 按值排序数组 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我正在為我的論壇創建一個“固定”功能,我正在尋找一種方法將我的固定主題放在數組的開頭,以便它們“卡在”頁面的頂部.

如果主題沒有固定,則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 – 按值排序数组的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。