0

即使在谷歌上进行了大量搜索后,我也无法理解如何对 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 的创建日期重新排列。

4

1 回答 1

0

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

$sql = "SELECT * FROM `bf_alert_stack` WHERE `type` = 'immediately' ORDER BY `created` DESC, `uid` ASC, `alert_id` DESC, `nid` DESC";
于 2013-04-03T15:03:17.863 回答