PHP log()

py9792289087's avatar
Published Jun 17, 2023
Contribute to Docs

The log() function returns the natural logarithm of a value.

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours

Syntax

$result = log(number,base);

Where number is the number whose logarithm is to be calculated and base is an optional parameter which signifies the logarithmic base to be used. By default base is e.

The value returned by the function is a float type.

Example

A basic implementation of the log() function:

<?php
echo(log(1));
?>

This will result in the following output:

0

Codebyte Example

Using log() to return the value of 5 base 10:

Code
Output

All contributors

Contribute to Docs

Learn PHP on Codecademy

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours