﻿ CodeForYoungs

# Php Mathematical Functions and Usage Examples

abs(): This is an absolute value function. It allows us to take the absolute value of value or variable inside.

Sample: echo abs(-7.2);  // Prints 7.2 value

base_convert(number,frombase,tobase): Converts numbers on different bases to each other

Sample: echo base_convert(5,10,2);  // Converts the number 5 in base 10 to  number 101 in base 2 and prints on the screen

bindec(): Converts binary number to base 10.

Sample: echo bindec(101); // Converts 101 in base 2 to the number 5 in base 10 and prints on the screen

ceil(): It is the function that rounds the value inside to the nearest upper integer.

Sample: echo ceil(-2.3);  // Prints value -2

floor(): It is the function that rounds the value inside down to the nearest integer.

Sample: echo floor(-2.3);  // Prints  value -3

max(): It is the function that gives the highest number in number serie.

Sample: echo max(3,5,9,2); // Prints value 9

sqrt(): It is the function that gives the square root of the value inside.

Sample: echo sqrt(9); // Prints value 3

pow(): It is a power function. It has 2 parameters in the form of pow (base,power).

Sample: echo pow(-3,2); // Prints value 9

rand(): It is a random integer number derivation function.

Sample:  echo rand(); // Generates and prints random number in integer value range

echo rand(2,20); // Generates and prints random integer numbers between 2 and 20

is_infinite(): Returns whether the value in it is infinite. Returns 0 if the value is infinite, 0 if not

Sample: echo is_infinitive(log(0));  // Prints value 1 because log (0) is infinite

is_finite(): Returns whether the value in it is finite. Returns 0 if the value is finite, or 0 if it is finite.

Sample: echo is_finitive(97);  // Prints value 1 because 97 is finitive number

is_nan(): Returns the value inside is not a number. Returns 0 if the value is not a number and 0 if the number is not

Sample: echo is_nan(2);  // Prints 0 or nothing, because 2 is a number

is_numeric(): Returns that the value in it is not a number. Returns 0 if the value is not a number and 0 if the number is not

Sample: echo is_numeric(2);  // Prints 1 because 2 is number

217 views