久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

php中按時間排序數組的問題

questions on sort array by time in php(php中按時間排序數組的問題)
本文介紹了php中按時間排序數組的問題的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

---數組 $points----

Array
    (
        [0] => Array
            (
                [0] => 2011-10-02 05:30:00
                [1] => 20
            )

        [1] => Array
            (
                [0] => 2011-10-04 09:30:00
                [1] => 12
            )

        [2] => Array
            (
                [0] => 2011-10-01 13:30:00
                [1] => 25
            )

        [3] => Array
            (
                [0] => 2011-10-03 02:30:00
                [1] => 31
            )

    )

我在上面有一個數組,想按時間對這個數組進行排序.然后我使用以下代碼進行排序并且結果是正確的.但是,如果我將代碼time[$key] = $val[0] 改為$time = $val[0],結果是錯誤的.

I have an array at above and would like to sort this array by time. Then I used the code as following to sort and result is correct. However, if I changed the code time[$key] = $val[0] to $time = $val[0], the result is wrong.

有沒有人可以向我解釋一下?非常感謝!

Is there anyone can explain this to me? Many thanks!

foreach($points as $key=>$val){

        $time[$key] = $val[0];

        array_multisort($time, SORT_ASC, $points);
    }

推薦答案

array_multisort 一次對多個數組進行排序.但是,它適用于列數組,因此需要 foreach 循環來獲取時間列.建立此列表后,您可以執行多重排序.$points 數組根據 $times 中的索引進行排序,按照 文檔中的這個例子.

array_multisort sorts more than one array at once. However, it works on an array of columns, so the foreach loop is needed to get a column of the times. After building up this list, you can then perform the multisort. The $points array is ordered according to the indices in $times, as per this example in the docs.

但是,您不需要在 foreach 中執行排序,因為這意味著排序發生了 4 次(在您的示例中).它只需要發生一次:

However, you don't need to perform the sort inside the foreach, as that means the sort happens 4 times (in your example). It only needs to happen once:

foreach ($points as $key => $val) {
    $time[$key] = $val[0];
}

array_multisort($time, SORT_ASC, $points);

這篇關于php中按時間排序數組的問題的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Action View Helper in Zend - Work around?(Zend 中的動作視圖助手 - 解決方法?)
Is this a good way to match URI to class/method in PHP for MVC(這是將 URI 與 PHP 中用于 MVC 的類/方法匹配的好方法嗎)
Where do I save partial (views) in Zend Framework, to be accessible for all Views in my App?(我在哪里保存 Zend Framework 中的部分(視圖),以便我的應用程序中的所有視圖都可以訪問?) - IT屋-程序員軟件開發技術
Having a single entry point to a website. Bad? Good? Non-issue?(有一個網站的單一入口點.壞的?好的?沒問題?)
Is MVC + Service Layer common in zend or PHP?(MVC + 服務層在 Zend 或 PHP 中常見嗎?)
Hello World example in MVC approach to PHP(PHP MVC 方法中的 Hello World 示例)
主站蜘蛛池模板: 久久久爽爽爽美女图片 | 91精品国产91久久综合桃花 | 黄色亚洲网站 | www.玖玖玖 | 亚洲精品乱码久久久久久按摩观 | 中文字幕电影在线观看 | 国产特黄一级 | 日韩一级在线 | 久久香蕉网| 国产精品乱码一区二区三区 | 久久亚洲一区二区三区四区 | 人人看人人草 | 99re视频 | 91在线免费视频 | 中文字幕亚洲国产 | 久久午夜剧场 | 在线观看av网站永久 | 自拍偷拍av| 国产高清精品在线 | 免费一区二区三区 | 青青久视频 | aⅴ色国产 欧美 | 久久久久久综合 | 久久亚洲一区 | 亚洲日韩中文字幕一区 | 亚洲激情一级片 | 日韩一区二区三区精品 | 成年人在线视频 | 黄色在线免费观看 | 99国产精品视频免费观看一公开 | 国产精品欧美精品日韩精品 | 99re在线观看 | 精品国产一区二区三区久久 | 国内久久精品 | 精品久久久久久 | 欧美 日韩 国产 成人 | 性一区| 爱爱无遮挡 | 久草精品视频 | 成人精品国产 | 久久成人国产精品 |