PHP log() function

12 Jan 2025 | 2 min read

The log() function is inbuilt php function, which is used to find the natural logarithm of a number or the logarithm of number to base.

Syntax:

ParameterDescriptionRequired /Optional
numberSpecify the value to calculate the logarithm.Required
basebase to use but default is 'e'Optional

Note: We get output as LOG of X if the input number with Base Y (optional) .

Example1

Output:

 Your number is: 2 By using log() function your number is : 0.69314718055995 

Example2

Output:

 Your number is: 2.7183 By using log() function your number is : 1.000006684914 

Example3

Output:

 Your number is: -1 By using log() function your number is : NAN 

Example4

Output:

 Your number is: 0 By using log() function your number is : -INF 

Note: Example of LOG() with Base.

Example5

Output:

 Your number is: log(5,2) By using log() function your number is : 2.3219280948874 

Example6

Output:

 Your number is: log(5,10) By using log() function your number is : 0.69897000433602 

Example7

Output:

 Your number is: log(5,2.7183) By using log() function your number is : 1.609427153552