久久久久久久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)
主站蜘蛛池模板: 青青草手机在线视频 | 91久久精品日日躁夜夜躁欧美 | 久久久久亚洲 | 亚洲一区二区在线视频 | a级片免费观看 | 日韩一区二区三区视频 | 国产精品毛片va一区二区三区 | 一区二区视频在线播放 | 日韩av免费在线观看 | 欧美日韩中文字幕 | 中文字幕在线一区二区三区 | 波多野结衣之双调教hd | av在线免费观看网址 | 成人欧美一区二区三区白人 | 一级特黄aaaaaa大片 | 久久久久一 | 久久夜色精品国产欧美乱极品 | 一区二区三区视频在线 | 一级黄色在线观看 | 国产毛片毛片毛片 | 日韩亚洲欧美在线 | 成人av在线看 | 午夜看看 | 日韩一区二区三 | 色综合色综合色综合 | 99精品在线| 天天干女人 | 国产精品永久久久久久久久久 | 一级黄片毛片 | 中文字幕在线观看不卡 | 欧美精品在线观看视频 | 在线免费看黄网站 | 性猛交xxxx富婆老太婆 | 99国产精品99久久久久久粉嫩 | 欧美精品黄色 | 欧美久久一区二区 | 午夜一级片 | 人人九九精 | 日韩av在线网站 | 免费网站av | 羞羞的视频在线观看 |