Math Log in PHP

In this article I explain the PHP math log function.
  • 1686

Introduction

The PHP math functions handle values within the range of integer and float types. In this article I describe PHP math log function.

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

log-math-function-in-php.jpg

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.