What is log10() in PHP?

The log10() function in PHP uses base 10 to calculate the logarithm of a number.

Figure 1, below, shows the mathematical representation of the log10() function and the corresponding representation in PHP.

Figure 1: Mathematical representation of the log10() function and the corresponding representation in PHP

Syntax


float log10(number)

Parameter

This function requires a number whose logarithm base 10 must be calculated and greater than zero.

  • If the number is zero, then this function outputs -Inf.

  • If the number is negative, this function outputs NaN.

Return value

log10() uses base 10 to return the logarithm of a number.

Code

<?php
echo("log10(10): ");
echo (log10(10));
echo("\n");
echo("log10(2): ");
echo (log10(2));
?>
<?php
#error outputs
echo("log10(0): ");
echo (log10(0));
echo("\n");
echo("log10(-1): ");
echo (log10(-1));
?>

Free Resources