PHP Max() 函数

PHP Max() 函数

max() 函数用于找出最高的值。

语法

max(array_values);

或者

max(value1,value2,value3,value4...);
名称 描述 必需/可选
array_values 指定包含数值的数组 必需
value1,value2,value3,value4… 指定要比较的数值(至少需两个值) 必需

PHP Max() 函数

示例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 valueb = 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

Camera课程

Python教程

Java教程

Web教程

数据库教程

图形图像教程

办公软件教程

Linux教程

计算机教程

大数据教程

开发工具教程