Math function in PHP

PHP Math function
  • PHP has a set of math functions that allows you to perform mathematical tasks on numbers.
PHP Math Functions list
  • In this topic, we will discuss commonly used functions of math.
  • PHP round() function
  • The round() function rounds a floating-point number to its nearest integer.

    <!DOCTYPE html>
    <html>
    <body>
    
    <?php
    echo "number 1 round : " . round(4.75);
    echo "<br/>";
    echo "number 2 round : " . round(2.45);
    ?>
    
    </body>
    </html>
    
  • PHP rand() function
  • The PHP rand() function is used to generate a random number.

    <!DOCTYPE html>
    <html>
    <body>
    
    <?php
    echo(rand());
    ?>
    
    </body>
    </html>
    


  • PHP sqrt() function
  • The PHP sqrt() function use to square root of a number.

    <!DOCTYPE html>
    <html>
    <body>
    
    <?php
    echo "Square root is : ".(sqrt(100));
    ?>
    
    </body>
    </html>
    

    Exercise: Other PHP math function list click here for see list.