久久久久久久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 | 国产女人第一次做爰毛片 | 久草欧美视频 | 国产污视频在线 | 酒色成人网 | 久久精品综合 | 日本高清视频在线播放 | 中文日韩在线视频 | 国产一区二区视频在线 | 国产激情偷乱视频一区二区三区 | 久久久精品在线 | 亚洲成人999 | 精品国产乱码久久久久久丨区2区 | 久久精品国产一区二区三区不卡 | 第一区在线观看免费国语入口 | 亚洲人久久 | www.亚洲成人网 | 国产免费av网 | 日韩免费一级 | 色必久久| 日韩一区在线播放 | 国产午夜精品一区二区三区 | 国产女人与拘做视频免费 | 亚洲视频中文字幕 | 日本中文字幕一区 | 久久亚洲一区二区 | 国产亚洲一区二区在线观看 | 国产中文字幕在线观看 | 免费午夜视频在线观看 | 亚洲不卡在线视频 | 精品国产18久久久久久二百 | 中文字幕亚洲欧美日韩在线不卡 | 精品免费视频 | 99精品欧美一区二区三区综合在线 | 99这里只有精品视频 | 成人av一区 | 日本网站免费观看 |