- Convert the array to an indexed array with array_values(). 2. A variable is defined to hold the maximum value, with the syntax “$m=$arr[0];”. ; 3, use the for statement to traverse the number of groups, syntax “for($I =0; $I < array length; $i++){… } “; 4, in the loop body, and constantly to “$m” compared with array each value, if the value is greater than the “$m” will be the value assigned to “$m” can, grammar “if ($arr ($I) > $m) {$m = $arr ($I); } “.
<!--?</span--> php
header('content-type:text/html; charset=utf-8');
function takeNum($array){
$arr=array_values($array);
// A variable $Max is defined to hold the maximum value
$max = $arr[0];
for ($i = 0; $i< count($arr); $i++){// loop arrays
if ($arr[$i] > $max) {
$max = $arr[$i];
}
}
Echo "maximum value is ".$Max;
}
$array = array(1=>"1","a"=>"5",2=>"3","b"=>0,"c"=>"4");
var_dump($array);
takeNum($array);
? >