根据特定字段名称对PHP数组进行排序

时间:2012-11-20 06:49:04

标签: php multidimensional-array sorting

Array
(
[0] =Array
    (
        [id] =3
        [title] =Tst topic 111 main
        [created] =2012-11-06 13:04:57
        [sticked] = 
        [forums_id] =1
        [status] =open
    )

[1] =Array
    (
        [id] =6
        [title] =Topic 222 Main
        [created] =2012-11-04 15:31:15
        [sticked] = 
        [forums_id] =1
        [status] =open
    )

[2] =Array
    (
        [id] =7
        [title] =dfgdfgdfg
        [created] =2012-11-19 13:27:10
        [sticked] =
        [forums_id] =1
        [status] =open
    )

[3] =Array
    (
        [id] =9
        [title] =sdf ertert ertwer
        [created] =2012-11-20 11:30:55
        [sticked] =2012-11-20 11:30:00
        [forums_id] =1
        [status] =&close
    )

[4] =Array
    (
        [id] =10
        [title] =345245
        [created] =2012-11-20 11:34:17
        [sticked] =2012-11-20 11:34:00
        [forums_id] =&1
        [status] =open
    )

)


这是我的结果多维数组。其中一些主题具有带有日期时间戳的sticked个字段。我想首先使用sticked字段(DESC顺序)对此数组进行排序,然后所有粘贴的主题将位于数组的顶部。然后我想用DES created字段命令所有具有空状态字段的数组。它是否可能?
我所期望的顺序是[4] - [3] - [2] - [0] - [1]

2 个答案:

答案 0 :(得分:0)

参考此页:

PHP数组排序函数

http://php.net/manual/en/array.sorting.php

答案 1 :(得分:-1)

只将此行添加到您的代码中

$final=arsort($yourarray);
print_r($final);

或者您可以在Link

看到帮助

愿它有用!!