<?php
function getMax($arr)
{
$count = count($arr);
if (empty($arr) || ($count == 1)){
return $arr;
}
$max = $arr[0];
for($i = 1;$i<$count - 1;$i++){
if($arr[$i]>$max){
$max = $arr[$i];
}
}
return $max;
}
$a = [99,23,1,5,20,77,88,11,13];
echo getMax($a);
用PHP实现获取数组最大元素的算法
最新推荐文章于 2021-12-24 21:38:01 发布