Skip to content

All topics  /  PHP

How To Use PHP Maths Function Example ?

PHP ·

Teams applying “How To Use PHP Maths Function Example ?” in a production project can use visit this page to record implementation, review and debugging time, then compare that effort with tests and shipped functionality instead of treating activity as performance by itself.

Before copying the example into a live application, confirm version-specific behaviour with the PHP project and test it against the project’s actual database and runtime.

Hi guys,

Today i will explained how to use php Maths function in your php file. This example is so easy to use in php. This example to i am use in many Maths function in php file.

THe maths function is provided in a php in by default. Maths function use to vary easy here.

This example to i am use in pi(),min(),max(),abs(),sqrt(),round(),rand() function used in this tutorial. So you are follow for my step by step.

So let's start to the example.

Pi() Function Example


Pi() function is return to the pi value.

<?php
    echo(pi());
    echo "<br>";
    // returns 3.1415926535898
?>

Output

3.1415926535898

Min() and Max() Function Example

Min() and Max() function is return to the minimun and maximum value return in the list

<?php
    echo(min(0, 150, 30, 20, -8, -200));  
    echo "<br>";
    // returns -200

    
    echo(max(0, 150, 30, 20, -8, -200));  
    echo "<br>";
    // returns 150
?>

Output

Min : -200
Max : -200

Abs() Function Example

Abs() function is only return to the absolute(positive) value return.

<?php
    echo(abs(-6.7));  
    echo "<br>";
    // returns 6.7
?>

Output

6.7

Sqrt() Function Example

Sqrt() function is return the square root of a number.

<?php
    echo(sqrt(64));  
    echo "<br>";
    // returns 8
?>

Output

8

Round() Function Example

Round() function is return the floating-point to nearest integer.

<?php
    echo(round(0.60));  
    echo "<br>";
    // returns 1

    
    echo(round(0.49));  
    echo "<br>";
    // returns 0
?>

Output

Round :1
Round :0

Rand() Function Example

Rand() function generates a random number and you are defind to minimum and maximum value defined then number generates in your number.

<?php
    echo(rand());           
    echo "<br>";
    // return 585927897

    
    echo(rand(10, 100));
    echo "<br>";
    // return 10
?>

Output

Rand :585927897
Rand :10

Now you can check your own.