簡體   English   中英

得到的最大值和相應的陣列的從陣列的PHP中的陣列的關鍵

[英]Get the maximum value and the key of the corresponding array from an array of arrays in PHP

對於這個令人困惑的問題,我真的很抱歉,但基本上我有一個由多個其他數組組成的 PHP 數組。 在這些數組中,我想在相關數組的 cpmbid 列中提取具有最大值的數組。

Array ( [0] => Array ( [cid] => 1 [accountid] => anaccount [orderid] => two [campaigntype] => CPM [bid] => 1.40000 [creativename] => Creative 2 [imgsource] => https://i1.wp.com/test-bucket-dfn.s3.us-west-2.amazonaws.com/wp-content/uploads/2019/07/24122252/NATPE-300x250.jpg?ssl=1 [clickthrough] => https://google.com/search?q=ad3 [targethostname] => localhost [targetpath] => all [keyvalue1] => my [keyvalue2] => any [keyvalue3] => any [width] => 300 [height] => 250 [dayrem] => 4 [clickrem] => 0 [imprem] => 1019 ) [1] => Array ( [cid] => 2 [accountid] => anaccount [orderid] => one [campaigntype] => CPM [bid] => 1.60000 [creativename] => Creative 2 [imgsource] => https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSm2kj7NQ0uuIxYqSA4-3dd1-I_x2xcpq2LmMfAcUOTG2AVv2n6bCkONgr1uVNJJO8EFIg&usqp=CAU [clickthrough] => https://google.com/search?q=ad2 [targethostname] => localhost [targetpath] => /home/no [keyvalue1] => hello [keyvalue2] => my [keyvalue3] => friend [width] => 300 [height] => 250 [dayrem] => 2 [clickrem] => 0 [imprem] => 753 ) [2] => Array ( [cid] => 3 [accountid] => anaccount [orderid] => three [campaigntype] => CPM [bid] => 2.30000 [creativename] => Creative 3 [imgsource] => https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRmZIh09uRp3ADOszQz6APBuCOmd6H_cQ-Dew&usqp=CAU [clickthrough] => https://google.com/search?q=ad4 [targethostname] => localhost [targetpath] => /fruitsalad/page.html [keyvalue1] => any [keyvalue2] => any [keyvalue3] => any [width] => 300 [height] => 250 [dayrem] => 2 [clickrem] => 0 [imprem] => 1000 ) [3] => Array ( [cid] => 4 [accountid] => anaccount [orderid] => two [campaigntype] => CPM [bid] => 1.90000 [creativename] => Creative 4 [imgsource] => https://i1.wp.com/test-bucket-dfn.s3.us-west-2.amazonaws.com/wp-content/uploads/2019/07/24122252/NATPE-300x250.jpg?ssl=1 [clickthrough] => https://google.com/search?q=ad5 [targethostname] => localhost [targetpath] => all [keyvalue1] => any [keyvalue2] => any [keyvalue3] => any [width] => 300 [height] => 250 [dayrem] => 4 [clickrem] => 0 [imprem] => 4013 ) )
//This is the Array, I want to select the array in which the highest 'bid' value is, any answers?

如果這是一個重復的問題,我很抱歉,我感謝任何答案。 謝謝!

您可以使用 array_column 獲取特定鍵的值數組,並將其最大化。

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

檢查以下代碼,它將根據值找到最大值,然后找到最大值數組:

$maxval=max(array_column($array,"bid")); 
$maxarray=array_keys(array_column($array,"bid"),$maxval);
print_R($array[$maxarray[0]]); 

$array = 你的數組,

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM