Home  >  Article  >  Backend Development  >  How to get the maximum value among several numbers in php

How to get the maximum value among several numbers in php

青灯夜游
青灯夜游Original
2021-11-09 18:02:322888browse

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 ,...);".

How to get the maximum value among several numbers in php

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:

How to get the maximum value among several numbers in php

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

How to get the maximum value among several numbers in php

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!

Statement:
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