php中在输入的数中找出最大值没有解决.希望得到大家的帮助解决方法

WBOY
Release: 2016-06-13 13:31:40
Original
774 people have browsed it

php中在输入的数中找出最大值没有解决.希望得到大家的帮助

error_reporting(E_ALL^E_NOTICE);
  $num=$_REQUEST['num1'];
echo '
'.$num;
$num=explode(" ",$num);
  $res=0;
  for($i=0;$i  
if($num[i]>$num[i+1]){
$res=$num[i];
}else{
$res=$num[i+1];
}


}



echo "最大值是".$res;


  /* foreach($num as $k=>$v){


}*/



?>

------解决方案--------------------
$num=explode(" ",$num);
echo "最大值是".max($num);
------解决方案--------------------
echo max(1, 3, 5, 6, 7); // 7
echo max(array(2, 4, 5)); // 5
echo max(0, 'hello'); // 0
echo max('hello', 0); // hello
echo max(-1, 'hello'); // hello

// 对多个数组,max 从左向右比较。
// 因此在本例中:2 == 2,但 4 $val = max(array(2, 4, 8), array(2, 5, 7)); // array(2, 5, 7)

// 如果同时给出数组和非数组作为参数,则总是将数组视为
// 最大值返回
$val = max('string', array(2, 5, 7), 42); // array(2, 5, 7)
?>
------解决方案--------------------
自己写,应这样

$res=0;
for($i=0;$i if($res }
echo "最大值是".$res;

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template