如何根据具体索引对三维数组进行排序?

时间:2013-04-02 09:46:28

标签: php multidimensional-array

即使在google上进行大量搜索后,我也无法理解如何对3维关联数组进行排序。

实际上,我想根据发布的工作日期对每个用户的提醒作业进行排序。

以下是代码:

$sql = "SELECT * FROM `bf_alert_stack` WHERE `type` = 'immediately'  order by created desc";


$q   = db_query($sql);

$user_alerts = array();

  while ($row  = db_fetch_array($q)) 
{   
   $user_alerts [$row['uid']]    [$row['alert_id']]  [$row['nid']] = $row['nid'];
}

在$ user_alerts数组中,$ row ['nid']包含特定用户警报的作业。

当用户在此时收到电子邮件提醒时,它应按照日期按排序顺序显示作业。

以下是来自$ user_alerts数组的示例数据

Array
(
    [144320] => Array
        (
            [3568728] => Array
                (
                    [30832] => 30832
                )

            [3568884] => Array
                (
                    [30837] => 30837
                    [30827] => 30827
                    [30828] => 30828
                    [30830] => 30830
                    [30831] => 30831
                    [30832] => 30832
                    [30838] => 30838
                    [30839] => 30839
                    [30826] => 30826
                    [30806] => 30806
                    [30808] => 30808
                    [30807] => 30807
                    [30698] => 30698
                    [30697] => 30697
                    [30601] => 30601
                )

        )

    [144330] => Array
        (
            [3568731] => Array
                (
                    [30827] => 30827
                    [30839] => 30839
                    [30838] => 30838
                    [30837] => 30837
                    [30832] => 30832
                    [30831] => 30831
                    [30830] => 30830
                    [30828] => 30828
                    [30826] => 30826
                    [30806] => 30806
                    [30808] => 30808
                    [30807] => 30807
                    [30698] => 30698
                    [30697] => 30697
                    [30601] => 30601
                )

        )

    [144218] => Array
        (
            [3568753] => Array
                (
                    [30808] => 30808
                )

        )

    [144216] => Array
        (
            [3568732] => Array
                (
                    [30808] => 30808
                )

        )

)

我想基于row ['nid']对这个上面的user_alerts数组进行排序,但是row ['nid']的详细信息在数据库表中。所有nid应该根据表中存在的nid的创建日期重新排列

1 个答案:

答案 0 :(得分:0)

这有点令人困惑,但也许偶然这会起作用..?

$sql = "SELECT * FROM `bf_alert_stack` WHERE `type` = 'immediately' ORDER BY `created` DESC, `uid` ASC, `alert_id` DESC, `nid` DESC";