1. Computing & Technology

Discuss in my forum

PHP Log () Function

By , About.com Guide

Definition: The Log () PHP Function is used to find logarithm. You can find either natural logarithm (using the base of e - which is approximately 2.71) or a logarithm of a specified base. If you specify a base you are really just doing logb(n) = log(n)/log(b). It is written as log(argument, base) so if you wanted to find the log2(8) you would write it as log(8,2).
Also Known As: Logarithm
Examples:
 <?php 
 echo(log(8,2) . "<br />"); 
 echo(log(8) . "<br />"); 
 echo(log(2) . "<br />"); 
 echo(log(8)/log(2) . "<br />"); 
 ?> 
 
This would return the results:
3
2.0794415416798
0.69314718055995
3

©2012 About.com. All rights reserved.

A part of The New York Times Company.