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

使用子鍵值對 PHP 數組進行排序

Sorting PHP array using subkey-values(使用子鍵值對 PHP 數組進行排序)
本文介紹了使用子鍵值對 PHP 數組進行排序的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有一個看起來像這樣的數組:

<前>大批([埃里克] => 數組([計數] => 10[變化] => 1)[Morten] => 數組([計數] => 8[變化] => 1))

現在,數組中的鍵是我們幫助臺系統中技術人員的姓名.我正在嘗試根據 [count] 加上 [changes] 的數量對其進行排序,然后顯示它們.我嘗試使用 usort,但隨后數組鍵被索引號替換.我該如何排序并保留數組鍵?

解決方案

你應該使用 uasort 來解決這個問題.

<塊引用>

bool uasort ( array &$array ,回調$cmp_function )

這個函數對一個數組進行排序,使得數組索引保持它們的與數組元素的相關性它們與,使用用戶定義的比較函數.這主要用于排序時關聯數組,其中實際元素順序很重要.

I have an array that looks something like this:

Array
(
    [Erik] => Array
    ( 
        [count] => 10
        [changes] => 1
    )
    [Morten] => Array
    (
        [count] => 8
        [changes] => 1
    )
)

Now, the keys in the array are names of technicians in our Helpdesk-system. I'm trying to sort this based on number of [count] plus [changes] and then show them. I've tried to use usort, but then the array keys are replaced by index numbers. How can I sort this and keep the array keys?

解決方案

You should use uasort for this.

bool uasort ( array &$array , callback $cmp_function )

This function sorts an array such that array indices maintain their correlation with the array elements they are associated with, using a user-defined comparison function. This is used mainly when sorting associative arrays where the actual element order is significant.

這篇關于使用子鍵值對 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社区在线观看播放 | 精品乱码一区二区三四区视频 | 日本午夜精品一区二区三区 | 99久久精品国产毛片 | 亚洲国产网 | 99精品在线观看 | 黑色丝袜三级在线播放 | a级免费视频| 日日欧美 | 欧美精品一区在线 | 日韩视频在线一区 | 91看片在线观看 | 手机在线一区二区三区 | 91高清在线观看 | www.久久久久久久久久久 | 成人一区二区三区 | 国产精品亚洲精品 | 国产高清一区二区三区 | 亚洲国产精品第一区二区 | 精品国产乱码久久久久久丨区2区 | 成人午夜精品一区二区三区 | 在线观看亚洲专区 | 国产精品一区二区三区四区 | 91看片网 | av国产精品 | 日韩成人一区 | 国产精品国产精品国产专区不卡 | 成人精品国产一区二区4080 | 一区二区久久电影 |