Overview
KB
Technical FAQ
PHP Manual
CSS2 Manual
HTML Manual
JS Guide
JS Reference
PhpDock Manual
Nu-Coder Manual
PhpExpress Manual
PHP Joomla
Development
Learn PHP
 
<is_nanlog10>
^Math FunctionsLast updated: Mon, 26 Oct 2026

log

(PHP 4, PHP 5, PHP 7, PHP 8)

log — Natural logarithm

Description

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

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

Parameters

num

The value to calculate the logarithm for

base

The optional logarithmic base to use (defaults to 'e' and so to the natural logarithm).

Return Values

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

Errors/Exceptions

Throws a ValueError if base is less than or equal to 0.

Changelog

Version Description
8.0.0 Now 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() - Base-10 logarithm
  • exp() - Calculates the exponent of e
  • pow() - Exponential expression
  • error_log() - Send an error message to the defined error handling routines


<is_nanlog10>
^Math FunctionsLast updated: Mon, 26 Oct 2026