Home >>PHP Math Functions >PHP log() Function

PHP log() Function

PHP log() Function

PHP log() function is used to calculate the natural logarithm of the given input number if no base is specified or the logarithm of the number to the specified base. It accepts at most two parameters $number and $base out of which one is required and the other one is optional. It returns the result of the given logarithmic operation.

Syntax:

  log($number,$base);

Parameter Values

Parameter Description
number This is a required parameter. This parameter defines the value to calculate the logarithm for.
base This is an optional parameter. This parameter defines the logarithmic base to use.

Here is an example of log() function in PHP:

<html>
<body>

<?php

echo log(0)."<br>";
echo log(1)."<br>";
echo log(2)."<br>";
echo log(10)."<br>";

?>

</body>
</html>
Output:
-INF
0
0.69314718055995
2.302585092994

Here is an another example of log() function in PHP:

<html>
<body>

<?php

echo log(1)."<br>";
echo log(1,10)."<br>";
echo log(10)."<br>";
echo log(10,10)."<br>";
echo log(20)."<br>";
echo log(20,10)."<br>";

?>

</body>
</html>
Output:
0
0
2.302585092994
1
2.995732273554
1.301029995664

No Sidebar ads