log()

py9792289087's avatar
Published Jun 17, 2023
Contribute to Docs

The log() function returns the natural logarithm of a value.

Syntax

$result = log(number,base);

Where number is the number whose logarithm is to be calculated and base is an optional parameter which signifies the logarithmic base to be used. By default base is e.

The value returned by the function is a float type.

Example

A basic implementation of the log() function:

<?php
echo(log(1));
?>

This will result in the following output:

0

Codebyte Example

Using log() to return the value of 5 base 10:

Code
Output
Loading...

All contributors

Contribute to Docs

Learn PHP on Codecademy