- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
PHP log10() Function
Definition and Usage
The log10 () function calculates base-10 logarithm of a number.
Base-10 logarithm is also called common or sandard algorithm. The log10(x) function calculates log10x. It is related to natural algorithm by following equation −
log10x=logex/loge10 So that
log10100=loge100/loge10 = 2
In PHP, log10 is represented by log10() function
Syntax
log10 ( float $arg ) : float
Parameters
Sr.No | Parameter & Description |
---|---|
1 | arg The number whose base-10 logarithm is to be calculated |
Return Values
PHP log10() function returns base-10 logarithm of arg.
PHP Version
This function is available in PHP versions 4.x, PHP 5.x as well as PHP 7.x.
Example
Following example calculates base-10 logarithm of 100
<?php $arg=100; echo "log10(" . $arg. ")=" . log10($arg) . "
"; ?>
Output
This will produce following result −
log10(100)=2
Example
Following code calculates base-10 logarithm of Euler Number M_E. The result is equal to a predefined constant M_LOG10E−
<?php $arg=M_E; echo "log10(" . $arg. ")=" . log10($arg) . "
"; echo "predefined constant M_LOG10E=" . M_LOG10E; ?>
Output
This will produce following result −
log10(2.718281828459)=0.43429448190325 predefined constant M_LOG10E=0.43429448190325
Example
Following example calculates log100 and returns -infinity. −
<?php $arg=0; echo "log10(" . $arg. ")=" . log10($arg) . "
"; ?>
Output
This will produce following result −
log10(0)=-INF
Example
Similarly sqrt(-1) results in NAN. Hence its log10() also returns NAN −
<?php $arg=sqrt(-1); echo "log10(" . $arg. ")=" . log10($arg) . "
"; ?>
Output
This will produce following result −
log10(NAN)=NAN