PHP Tutorial - PHP log() Function






Definition

The log() function returns the natural logarithm of a number, or the logarithm of number to base.

Syntax

PHP log() Function has the following syntax.

log(number,base);

Parameter

ParameterIs RequiredDescription
numberRequired. Value to calculate the logarithm for
baseOptional. The logarithmic base to use. Default is 'e'

Return

Item Description
Return Value The natural logarithm of a number, or the logarithm of number to base
Return TypeFloat




Example

Return the natural logarithm of different numbers:


<?php
echo log(2.7183) . "\n";
echo log(2) . "\n";
echo log(1) . "\n";
echo log(0);
?>

The code above generates the following result.