In PHP, you can use the max() function to get the maximum value among several numbers. The function of this function is to calculate and return the maximum value among several specified values. The syntax "max(value1,value2 ,...);".
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
In php, you can use the max() function to get the maximum value among several numbers.
This function can calculate and return the maximum value among several specified values.
Syntax:
max(value1,value2,...);
value1,value2,...
: Required. Specifies the values to be compared (at least two values).
Example:
<?php echo(max(2,4,6,8,10) . "<br>"); echo(max(22,14,68,18,15) . "<br>"); ?>
Output result:
If you don’t want to pass the value to the max() function , or you can combine these values into an array and pass the array name to the max() function.
max() function also returns the maximum value in an array, syntax:
max(array_values);
Example:
<?php echo(max(array(4,6,8,10)) . "<br>"); echo(max(array(44,16,81,12))); ?>
Recommended learning: " PHP video tutorial》
The above is the detailed content of How to get the maximum value among several numbers in php. For more information, please follow other related articles on the PHP Chinese website!