PHP Tutorial

Define PHP

PHP Installation

PHP INI File

PHP Comment

PHP Case Sensitivity

PHP Variable, DataType

PHP Echo & Print

PHP Operators

PHP Receiving Input

Decision Making - if...else

PHP Switch Case

PHP Loops

PHP Jumping Statement

PHP Image Gallery

PHP File Upload

PHP Arrays

PHP Date Functions

PHP String Functions

PHP Math Functions

PHP Functions

PHP Variable Scope

PHP Constant Variable

PHP Superglobals

PHP Form Validation

PHP Include Statement

PHP Filter

PHP File Handling

PHP Cookies

PHP Session

PHP Send Emails

PHP Captcha

PHP MySQL Select

PHP MySQL Insert

PHP MySQL Delete

PHP MySQL Update

PHP MySQL Injection

PHP Assignment

Page Stats

Visitor: 408

PHP Math Functions

PHP Math Functions are use to perform some mathematical operations on integer and float values.

Built-in PHP Math Functions version 4+:
S.No. Function Description
abs() Returns the absolute (positive) value of a number
ceil() Round number up to the nearest integer.
floor() Round number down to the nearest integer.
round() Round the number.
max() Returns the largest number from an array.
min() Returns the smallest number from an array.
fmod() Returns the remainder (modulo)
pi()
M_PI
Return the value of PI.
rand()
mt_rand()
Generate random numbers.
mt_rand() function is 4 times faster than rand() function.
pow() Return x raised to the power y.
sqrt() Return the square root of a number.
sin() Return the sine value of a number.
cos() Return the cosine value of a number.
tan() Return the tangent value of a number.

Abs() Function

echo(abs(10.5)); //return 10.5
echo(abs(-10.5)); //return 10.5

Ceil Function

echo(ceil(5.1)); //return 6 

Floor Function

echo(floor(5.9)); //return 5

Round Function

echo(round(10.50)); //return 11
echo(round(10.49)); //return 10
echo(round(10.34726,2)); //return 10.35

Max Function

echo(max(array(33,67,23,78,47))); //return 78
echo(max(33,67,23,78,47)); //return 78

Min Function

echo(min(array(33,67,23,78,47))); //return 23
echo(min(33,67,23,78,47)); //return 23

Fmod Function

echo(fmod(5,2)); //return 1

Pi Function

echo(pi()); //return 3.1415926535898

Rand Function

echo(rand());
echo(getrandmax()); 
echo(rand(10,20)); //return random number between 10 and 20

Pow Function

echo(pow(2,10)); //return 1024

Sqrt Function

echo(sqrt(25)); //return 5

Sin Function

echo(sin(90)); //return 0.89399 
echo(sin(90*(M_PI/180))); //return 1 after converting radian to degree

Cos Function

echo(cos(45));
echo(cos(90*(M_PI/180)));

Tan Function

echo(tan(45));
echo(cos(90*(M_PI/180)));