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.

Scroll to Top

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

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.