返回数组中最大值的索引 [英] Return index of highest value in an array

查看:28
本文介绍了返回数组中最大值的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从类似于以下内容的数组中,如何获取数组中最大值的索引.对于下面的数组,所需的结果是11".

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
)

推荐答案

我的解决方案是:

$maxs = array_keys($array, max($array))

注意:
通过这种方式,您可以检索与给定最大值相关的每个键.

如果您只对一个键感兴趣,只需使用$maxs[0]

If you are interested only in one key among all simply use $maxs[0]

这篇关于返回数组中最大值的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆