久久久久久久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在线观看 | 久久国产精品免费 | 欧美综合在线视频 | 一区二区三区回区在观看免费视频 | 亚洲精品黄色 | 国产精品久久久久久久久久久久久 | 精品网站999www | 九九亚洲 | 国产美女特级嫩嫩嫩bbb片 | 国产精品久久久久久久岛一牛影视 | 国户精品久久久久久久久久久不卡 | 91热在线 | 免费黄色的网站 | 亚洲午夜精品一区二区三区他趣 | 久久草在线视频 | 91在线免费视频 | 成人免费激情视频 | 国产成人精品一区二 | 日日骚视频 | h视频在线看| av毛片在线播放 | 国产精品久久久久久久久久久久 | 午夜激情一区 | 99国内精品| 国产h视频 | 国产9 9在线 | 中文 | 国产精品亚洲欧美日韩一区在线 | 免费在线观看一级毛片 | 色网在线看 | 中文字幕国产视频 | 久久99久久99久久 | 国产日韩欧美精品一区二区 | 日本一区二区三区四区 | 亚洲精品久久久一区二区三区 | 老司机深夜福利网站 | 91网站在线看 | 日本在线观看视频 | av在线免费网 |