Home >>PHP Math Functions >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 | 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>
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>