How does PHP use a for loop to maximize an array

  1. 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){

// 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");
? >

Leave a Reply

Your email address will not be published. Required fields are marked *