log()

log() — Natural logarithm.

Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

What it does

If the optional base parameter is specified, log() returns logbase num, otherwise log() returns the natural logarithm of num.

Signature

log(float $num, float $base = M_E): float

Parameters

ParameterTypeWhat it takes
$numfloatThe value to calculate the logarithm for
$basefloatThe optional logarithmic base to use (defaults to 'e' and so to the natural logarithm).

Return value

The logarithm of num to base, if given, or the natural logarithm.

Example

The PHP manual ships no example for log(); the signature and the parameter table above are the contract.

Changelog

VersionChange
8.0.0Now throws a ValueError if base is less than or equal to 0. Previously, an E_WARNING was raised and false was returned.

See also

log10(), exp(), pow(), error_log()

All PHP 8.5 built-in functions

Reference card built from the PHP manual page log() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.