PHP log() Function

In this chapter you will learn:

  1. Definition for PHP log() Function
  2. Syntax for PHP log() Function
  3. Parameter for PHP log() Function
  4. Return for PHP log() Function
  5. Example - Return the natural logarithm of different numbers

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/*  java2 s  . c  om*/
echo log(2.7183) . "\n";
echo log(2) . "\n";
echo log(1) . "\n";
echo log(0);
?>

The code above generates the following result.

Next chapter...

What you will learn in the next chapter:

  1. Definition for PHP log10() Function
  2. Syntax for PHP log10() Function
  3. Parameter for PHP log10() Function
  4. Return for PHP log10() Function
  5. Example - Return the base-10 logarithm of different numbers