当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


PHP Max()用法及代码示例


max() 函数用于查找最大值。

用法:

max(array_values);

OR

max(value1,value2,value3,value4...);
名称 描述 必需/可选
array_values 指定包含值的数组 Required
值1、值2、值3、值4... 指定要比较的值(必须至少有两个值 Required
PHP math Max function

示例 1

<?php
$num=max(4,14,3,5,14.2);
echo "Your number is =max(4,14,3,5,14.2)".'<br>';
echo "By using max function Your number is:".$num;
?>

输出:

Your number is =max(4,14,3,5,14.2)
By using max function Your number is:14.2

例2

<?php
$num=max(.1, .001, .2, -.5);
echo "Your number is =max(.1, .001, .2, -.5)".'<br>';
echo "By using max function Your number is:".$num;
?>

输出:

Your number is =max(.1, .001, .2, -.5)
By using max function Your number is:0.2

例3

<?php
$arr= array(110, 20, 52 ,105, 56, 89, 96);
echo "Your number is =array(110, 20, 52 ,105, 56, 89, 96)".'<br>';
echo "By using max() function Your number is:".max($arr);
?>

输出:

Your number is =array(110, 20, 52 ,105, 56, 89, 96)
By using max() function Your number is:110

例4

<?php
$arr= array(200, 120, 52 ,105, 56, 89, 94);
//using forloop find the max value
$b = 0;
for($i=0;$i<count($arr);$i++)
 {
    if ($arr[$i] > $b)
	{
        $b = $arr[$i];
    }
}	
echo "By using max() function Your number is:".$b;
?>

输出:

By using max() function Your number is:200






相关用法


注:本文由纯净天空筛选整理自 PHP Max() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。