Skip to main content

How to Get Min or Max Value of an Array in PHP?

In order to get the minimum or maximum value in an array, we need to use a function that will calculate this for us. The min() and max() functions will return the smallest or largest value in an array, respectively. This can be helpful for determining the best or worst value in a set of data, or for finding the largest or smallest value in a series of numbers.

$numbers = [1, 2, 3, 4, 5];
echo min($numbers); // Outputs 1
echo max($numbers); // Outputs 5

As you can see, these functions are quite simple to use. Just pass in the array that you want to find the minimum or maximum value of and it will return the appropriate value.

By continuing to use the site, you agree to the use of cookies.