Logarithm is the counter operation to exponentiation. The logarithm of a number is in fact the exponent to which the other number i.e. the base must be raised to produce that number. If the Euler’s Number ‘e’ is used as the base of any logarithmic operation it is then known as Natural Logarithmic Operation, another popular logarithmic operation is to take 10 as the base.
In PHP, the log() function is used to calculate the natural logarithm of a number if no base is specified and the log10() function calculates the base 10 logarithm of a number.
float log ($arg, $base)
Parameters: The function can accept at most two parameters as follows:
- $arg: This is a required parameter that refers to the number of whose the logarithm is to be calculated.
- $base: This is an optional parameter that refers to the base of the logarithmic operation. If not given, M_E i.e. the Euler’s Number is used as Base to calculate the Natural Logarithm.
Return Type: This function returns the result of the logarithmic operation.
Input : $arg = M_E * M_E; Output : 2 Input : $arg = 1024; $base = 2; Output : 10
Below program illustrates the working of log() in PHP:
log(81, 3) = 4 log(81, 9) = 2 log(81, 81) = 1
float log ($arg)
Parameters: The function accepts a single parameter $arg which refers to the number of whose the logarithm is to be calculated.
Return Type: This function returns the result of the Base 10 logarithmic operation.
Input : $arg = 100; Output : 2 Input : $arg = 10000; $base = 4; Output : 10
Below program illustrates the working of log10() in PHP:
log10(100000) = 5 log10(10000) = 4 log10(1000) = 3 log10(100) = 2 log10(10) = 1
Important points to note:
- log() function is a very popular method to calculate logarithmic values.
- PHP | exp() function is the functional counterpart of log().
- PHP Math Functions (is_nan, pow, sqrt, exp, log, log10, log1p, max, min, getrandmax, rand, mt_rand)
- Difference between regular functions and arrow functions
- PHP | Functions
- PHP | String Functions
- PHP | die() & sleep() functions
- PHP | GMP Functions Complete Reference
- PHP | startsWith() and endsWith() Functions
- jQuery | Callback Functions
- PHP | Ds\Map Functions Complete Reference
- PHP | Ds\Set Functions Complete Reference
- CSS | Functions Complete Reference
- How to add many functions in one ng-click directive?
- PHP | strrpos() and strripos() Functions
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.