Introduction
The PHP math functions handle values within the range of integer and float types. In this article I describe some of the PHP math functions. To learn about some other MATH functions, go to PART 1 , PART 2 and PART 3.
PHP log() function
The PHP math log function is used to return the natural logarithm (base E) of a number.
Syntax
| log( number, base) |
Parameters in log function
It takes two parameters; they are:
| Parameter | Description |
| number | It specifies a number. |
| base | The optional logarithmic base to use (defaults to "e" and so to the natural logarithm). |
Example of log function
<?php
$val1=log(2);
$val2=log(0);
$val3=log(1.232);
$val4=log(1);
echo "log value of <b>2</b> is <b>$val1</b> <br />";
echo "log value of <b>0</b> is <b>$val2</b> <br />";
echo "log value of <b>1.232</b> is <b>$val3</b> <br />";
echo "log value of <b>1</b> is <b>$val4</b> <br />";
?>
Note: The code above is used to convert numbers to the natural logarithm (base E) of a number. So in the above example the numbers "2", "0", "1.232" and "1" are converted to the natural logarithm of the number.
Output
PHP log10() function
The PHP math log function is used to return the base-10 logarithm of a number.
Syntax
| log10( number) |
Parameters in log10 function
It takes one parameter; it is:
| Parameter | Description |
| number | It specifies a number. |
Example of log10 function
<?php
$val1=log10(2);



Comments
Join the conversation! Your thoughts help the community grow.