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

在多維數組中查找最大值

Find highest value in multidimensional array(在多維數組中查找最大值)
本文介紹了在多維數組中查找最大值的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

問題

我有一個類似于下面的多維數組.我想要實現的是一種從數組中查找和檢索具有最高總"值的方法,現在我知道有一個名為 max 的函數,但它不適用于像這樣的多維數組.

I have a multidimensional array similar to the one below. What I'm trying to achieve is a way to find and retrieve from the array the one with the highest "Total" value, now I know there's a function called max but that doesn't work with a multidimensional array like this.

我想做的是創建一個 foreach 循環并構建一個只有總數的新數組,然后使用 max 找到最大值,這會起作用,唯一的問題是檢索與該最大值相關的其余數據.我也不確定這是最有效的方法.

What I've thought about doing is creating a foreach loop and building a new array with only the totals, then using max to find the max value, which would work, the only issue would then be retrieving the rest of the data which relates to that max value. I'm not sure that's the most efficient way either.

有什么想法嗎?

Array
(
    [0] => Array
        (
            [Key1] => Key1
            [Total] => 13
        )

    [1] => Array
        (
            [Key2] => Key2
            [Total] => 117
        )

    [2] => Array
        (
            [Key3] => Key3
            [Total] => 39
        )
)

推薦答案

自 PHP 5.5 起,您可以使用 array_column 獲取特定鍵的值數組,并將其最大化.

Since PHP 5.5 you can use array_column to get an array of values for specific key, and max it.

max(array_column($array, 'Total'))

這篇關于在多維數組中查找最大值的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

Joining 2 tables in SELECT(MYSQL/PHP)(在 SELECT(MYSQL/PHP) 中加入 2 個表)
How to make lt;option selected=quot;selectedquot;gt; set by MySQL and PHP?(如何使lt;option selected=“selectedgt;由 MySQL 和 PHP 設置?)
Auto populate a select box using an array in PHP(使用 PHP 中的數組自動填充選擇框)
PHP SQL SELECT where like search item with multiple words(PHP SQL SELECT where like search item with multiple words)
json_encode produce JSON_ERROR_UTF8 from MSSQL-SELECT(json_encode 從 MSSQL-SELECT 產生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名稱 ASC)
主站蜘蛛池模板: 天天搞天天搞 | 久草视频观看 | 久久久人成影片一区二区三区 | 国产成人网 | 日韩在线视频一区 | 女同久久另类99精品国产 | 91免费在线视频 | 久久精品日产第一区二区三区 | 中文成人在线 | 中文字幕在线一区二区三区 | 精品国产乱码久久久久久中文 | 日韩午夜 | 日韩免费一区二区 | 美女黄18岁以下禁止观看 | 国产视频一二三区 | 成人在线视频免费观看 | 亚洲一区二区在线电影 | 四虎影音 | 免费国产成人av | 中文字幕av一区 | 国产二区三区 | 欧美国产日韩一区 | 97精品久久 | 日韩www | 91精品国产综合久久福利软件 | 免费国产一区 | 日韩av一区二区在线 | 国产日韩欧美二区 | 精品91视频 | 综合网伊人 | 自拍偷拍第1页 | 青青草视频网站 | 亚洲成人在线免费 | 人人看人人草 | 欧美黄色一级毛片 | 精品久久久久一区二区国产 | 桃花av在线 | 日韩蜜桃视频 | 毛片一级片 | 国产高清在线观看 | 超碰婷婷 |