PHP log10() Function
The PHP log10() function returns the base-10 logarithm of a given number. In special cases it returns the following:
- If the argument is NAN or less than zero, then the result is NAN.
- If the argument is positive infinity, then the result is positive infinity.
- If the argument is zero, then the result is negative infinity.
Syntax
log10(number)
Parameters
number |
Required. Specify the number. |
Return Value
Returns the base-10 logarithm of a given number.
Example:
In the example below, log10() function is used to calculate the base-10 logarithm of a given number.
<?php echo "log10(0) = ".log10(0)."\n"; echo "log10(0.5) = ".log10(0.5)."\n"; echo "log10(1) = ".log10(1)."\n"; echo "log10(10) = ".log10(10)."\n"; echo "log10(100) = ".log10(100)."\n"; echo "log10(INF) = ".log10(INF)."\n"; echo "log10(-INF) = ".log10(-INF)."\n"; echo "log10(NAN) = ".log10(NAN)."\n"; ?>
The output of the above code will be:
log10(0) = -INF log10(0.5) = -0.30102999566398 log10(1) = 0 log10(10) = 1 log10(100) = 2 log10(INF) = INF log10(-INF) = NAN log10(NAN) = NAN
❮ PHP Math Reference