我有一个数组,我想找到最大数字的索引,并在PHP中显示索引

时间:2014-11-02 00:58:11

标签: php arrays indexing

我已使用此arrayfunction来查找最大数字:

$nums=array(9,3,1,0,99,2,5,6,32,1,55);

function big($big) {
    echo "The highest value is: ";
    echo max($big);
    echo "<br>";
}

1 个答案:

答案 0 :(得分:0)

这很简单,只需使用array_search();,然后您就可以再次使用max();

<?php

    $nums = array(9, 3, 1, 0, 99, 2, 5, 6, 32, 1, 55, 11);

    echo "The highest key is: ";
    echo array_search(max($nums), $nums);
    echo "<br />";


?>

输出:

4