Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

log

Calculates the logarithm of a number.

Syntax

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

Parameters

ParameterTypeDescription
$numfloatThe number.
$basefloatOptional. The base; the natural logarithm by default.

Return value

floatThe logarithm.

Examples

How many doublings turn 1 into 1024:

<?php
 
echo log(1024, 2), "\n";
echo log10(1000), "\n";
echo round(log(M_E), 2);

Output:

10
3
1

Notes

For bases 10 and 2 there are the exact log10() and log2() functions.

See also

  • exp — Raises the number e to a power.
  • pow — Raises a number to a power.
  • sqrt — Returns the square root of a number.

In the tutorial

  • Numbers and maths — PHP's maths functions — rounding, number formatting, random numbers and the precision of fractions.

Thanks for reading!

Donate to the site — we work hard for you.