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


I have one array and i want to find the index of biggest number and display the index in PHP

我用这个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>";
}

很简单,只需使用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
相关文章: