log
Calculates the logarithm of a number.
Syntax
log(float $num, float $base = M_E): floatParameters
| Parameter | Type | Description |
|---|---|---|
| $num | float | The number. |
| $base | float | Optional. 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
1Notes
For bases 10 and 2 there are the exact log10() and log2() functions.
See also
In the tutorial
- Numbers and maths — PHP's maths functions — rounding, number formatting, random numbers and the precision of fractions.