Math Function :

1. abs() :
Syntax number abs (mixed number);
example :

abs(-4.2);

Explanation:

Finding the Absolute value of the given number.

  	
	<?php
	    $absolute = abs(-8.21);
            print $absolute;
	    $absolute = abs(8.21);
            print "
".$absolute; ?>
Output :
8.21
8.21
2. base_convert():
Syntax string base_convert(number, base of the given number, converted base );
It returns a string type from one base to another base.
Example:

base_convert('A37334', 16, 2);

Explanation:

Converts the number from one base to another base.

  	
<?php
     $hexadecimal = 'A37334';
     print base_convert($hexadecimal, 16, 2);
     $strval = '50';
     print "
".base_convert($strval, 10, 16); ?>
Output :
101000110111001100110100
32

Other predefined base convertor functions are present in PHP like decbin(), bindec(), dechex(), hexdec(), decoct(), octdec()

3. floor() :
Syntax float floor(float value);
It returns a integer value.
Example :

floor(4.3);
floor(9.999);
floor(-3.14);

Explanation :

It prints the whole number part if the number is positive otherwise add -1 to the whole number part.

  	
<?php
    print floor(4.3);   
    print floor(9.999); 
    print floor(-3.14); 
?>
Output :
4 9 -4
4. ceil() :
Syntax float ceil(float value);
It returns a integer value.
example :

ceil(4.3);
ceil(9.999);
ceil(-3.14);

Explanation :

Returns the next highest integer value by rounding up value if necessary.

  	
<?php
    print ceil(4.3);   
    print ceil(9.999); 
    print ceil(-3.14); 
?>
Output :
5 10 -3
5. is_finite() :
Syntax bool is_finite(float val);
Its return type is boolean either true or false.
Example :

is_finite(121323422323);

Explanation :

Checks the value is finite or not.

  	
<?php
    print is_finite(1233);  
    print "
".is_finite(log(0)); ?>
Output :
1
  (blank)
6. is_nan() :
Syntax bool is_nan ( float val );
Its return type is boolean either true or false.
Example :

is_nan ( 5.1225 );

Explanation :

Returns TRUE if val is 'not a number', else FALSE.

  	
<?php
    print is_nan(1233); 
    print is_nan(acos(1.01));
?>
Output :
(blank)
1
7. max() :
Syntax max(list of numbers);
example :

max(1, 3, 5, 6, 7);

Explanation :

Finds the greatest value from the list of numbers.

  	
<?php
    print max(1, 3, 5, 6, 7)."
"; print max(array(2, 4, 5))."
"; print max(0, 'hello')."
"; //Explanation is that :- Any Non numeric value treated as 0 ,So max and min function comparing from the left to right. print max('hello', 0)."
"; print max(-1, 'hello')."
"; // With multiple arrays, max compares from left to right // so in our Example: 2 == 2, but 4 < 5 $val = max(array(2, 4, 8), array(2, 5, 7)); print_r($val); print "
"; // If both an array and non-array are given, the array // is always returned as its seen as the largest $val1 = max('string', array(2, 5, 7), 42); print_r($val1); ?>
Output :
7
5
0
hello
hello
Array ( [0] => 2 [1] => 5 [2] => 7 )
Array ( [0] => 2 [1] => 5 [2] => 7 )
8. min() :
Syntax min( list of numbers);
example :

min(1, 3, 5, 6, 7);

Explanation :

Finds the smallest value from the list of numbers.

  	
<?php
    print min(2, 3, 1, 6, 7)."
"; print min(array(2, 4, 5))."
"; print min(0, 'hello')."
"; print min('hello', 0)."
"; print min('hello', -1)."
"; // With multiple arrays, min compares from left to right // so in our Example: 2 == 2, but 4 < 5 $val = min(array(2, 4, 8), array(2, 5, 1)); print_r($val); print "
"; // If both an array and non-array are given, the array // is never returned as its considered the largest $val1 = min('string', array(2, 5, 7), 42); print_r($val1); ?>
Output :
1
2
0
hello
-1
Array ( [0] => 2 [1] => 4 [2] => 8 )
string
9. rand() :
Syntax int rand(min, max);
It returns an integer value.
example :

rand(12,15);

Explanation :

Showing any random number between these two given number including two given number.

  	
<?php
    print rand()."
"; print rand()."
"; print "minimum number is 5"."
"; print "maximum number is 15"."
"; $random = rand(5, 15); print "Random number is " .$random."
"; ?>
Output :
1764336074
2009967715
minimum number is 5
maximum number is 15
Random number is 11
Note :The above output value is not fixed,the value will change each time.
10. pow() :
Syntax float pow(base, power);
It retun a float value.
example :

pow(8,2);

Explanation :

It finds the power of given base to the power.

  	
<?php
    var_dump(pow(2, 8))."
"; print pow(-1, 20)."
"; print pow(0, 0)."
"; print pow(3,2); ?>
Output :
int(256)
1
1
9
11. sqrt() :
Syntax float sqrt(int number);
It returns a float value.
example :

strtosqrt(9);

Explanation :

Finds the square root of a number.

  	
<?php
    // Precision depends on your precision directive
    print sqrt(9)."
"; print sqrt(10)."
"; ?>
Output :
3
3.16227766 ...
12. round() :
Syntax float round( float val [, int precision]) ;
It return a float value.
example :

round(3.45);

Explanation :

Returns the rounded value of val to specified precision (number of digits after the decimal point). precision can also be negative or zero (default).

  	
<?php
    echo round(3.4)."
"; echo round(3.5)."
"; echo round(3.6)."
"; echo round(3.6, 0)."
"; echo round(1.95583, 2)."
"; echo round(1241757, -3)."
"; echo round(5.045, 2)."
"; echo round(5.055, 2)."
"; ?>
Output :
3
4
4
4
1.96
1242000
5.05
5.06

Questions

  1. Get the output for max(0, 'sameer', 'pawan');?
  2. Write code for Round up 5.88990 upto 3 digits after decimal point ?
After editing Click here:
Output:
Hello World