log()

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:

us
Visit us
code
Hide code
Code
Output
Hide output
Hide output
Loading...

All contributors

Looking to contribute?

Learn PHP on Codecademy