返回最高值的指数在一个数组 [英] Return index of highest value in an array
本文介绍了返回最高值的指数在一个数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是一个数组,看起来像下面,我怎样才能在阵列中的最高值的索引。对于下面的阵列,所需要的结果将是11。
阵列( [11] => 14
[10] => 9
[12] => 7
[13] => 7
[14] => 4
[15] => 6
)
块引用>解决方案我的解决办法是:
$ MAXS = array_keys($阵列,MAX($阵列))
注:的
这种方式,您可以检索的每一个关键与给定的最大值的。如果你只关心的之间的所有一键的简单使用 $ MAXS [0]
From an array that looks something like the following, how can I get the index of the highest value in the array. For the array below, the desired result would be '11'.
Array ( [11] => 14 [10] => 9 [12] => 7 [13] => 7 [14] => 4 [15] => 6 )
解决方案My solution is:
$maxs = array_keys($array, max($array))
Note:
this way you can retrieve every key related to a given max value.If you are interested only in one key among all simply use $maxs[0]
这篇关于返回最高值的指数在一个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文