Math Functions in PHP: Part 6


Introduction

The PHP math functions are used to handle values within the range of integers and float types. In this article I describe some of the PHP math functions. To know some other math functions, go to:


  1. Math Function in PHP:Part 1
  2. Math Functions in PHP:Part 2 
  3. Math Functions in PHP:Part 3 
  4. Math Functions in PHP: Part 4
  5. Math Functions in PHP: Part 5
PHP max() function

The PHP math max function is used to return the highest value from a set of expressions.

Syntax
max( array)
OR
max(number1, number2....)


Parameters in

max function

The parameters of the max function are:
 

Parameter Description
array It specifies a array.
OR
number1, number2
It specifies numbers( at least two number is required).


Example of max function

 

The following sample of the max function obtains the highest number of two or more numbers. The highest number specified in each function is returned.

 

<?php

$val1=max(34,4,90,6,78);

$val2=max(1,2);

$val3=max('abcd','dsef','fgre');

$val4=max(array(1,-2,5,8));

echo "max value of <b>max(34,4,32,6,78)</b> is <b>$val1</b> <br />";

echo "max value of <b>max(1,2)</b> is <b>$val2</b> <br />";

echo "max value of <b>max('abcd','dsef','fgre')</b> is <b>$val3</b> <br />";

echo "max value of <b>max(array(1,-2,5,8))</b> is <b>$val4</b> <br />";

?>


Output

math-max-function-in-php.jpg

PHP min() function

The PHP math min function is used to return the minimum value from a set of expressions.

Syntax

min( array)
OR
min(number1, number2....)


Parameters in

min function

The parameters of the "min" function are:
 

Parameter Description
array It specifies a array.
OR
number1, number2
It specifies numbers( at least two number is required).


Example of min function

 

The following sample of the min function obtains the lowest number of two or more numbers. The lowest number specified in each function is returned.


<?
php
$
val1=min(34,4,90,6,78);
$
val2=min(1,2);
$
val3=min('abcd','dsef','fgre');
$val4=min(array(1,-2,5,8));
echo "min value of
<b>min(34,4,32,6,78)</b> is <b>$val1</b> <br />";
echo "min value of
<b>min(1,2)</b> is <b>$val2</b> <br />";
echo "min value of
<b>min('abcd','dsef','fgre')</b> is <b>$val3</b> <br />";
echo "min value of
<b>min(array(1,-2,5,8))</b> is <b>$val4</b> <br />";
?>


Output

math-min-function-in-php.jpg

PHP mt_getranmax function

The PHP math mt_getranmax function is used to return the maximum value that can be returned by the mt_rand() function.

Syntax

mt_getrangmax()


Example of mt_getranmax  function

 

The following is an example of the mt_getranmax  function:



<?
php
$
val=mt_getrandmax();
echo
"Maximum value of mt_getrandmax() function is  <b> $val</b>";
?>

Output

math-mt-getrandmax-function-in-php.jpg


Similar Articles