PHP Math

PHP Math

PHP has a set of built-in math functions that allow you to perform mathematical tasks on numbers easily.


Finding Min and Max Values

The min() and max() functions can be used to find the lowest or highest value in a list of arguments.

Example

<?php
echo "The max is: " . max(0, 150, 30, 20, -8, -200) . "\n";
echo "The min is: " . min(0, 150, 30, 20, -8, -200);
?>

PHP round() and abs()

PHP Random Numbers

The rand() function generates a random number. If you want a random integer between a specific range, you can pass parameters to the function.

Example

<?php
// Generate a random number between 10 and 100
echo rand(10, 100);
?>