How to get the maximum value among several numbers in php

青灯夜游
Release: 2023-03-13 19:06:02
Original
2897 people have browsed it

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,...);
Copy after login
  • 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>");
?>
Copy after login

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);
Copy after login

Example:

<?php
echo(max(array(4,6,8,10)) . "<br>");
echo(max(array(44,16,81,12)));
?>
Copy after login

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!

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