Math Functions in PHP

Performing mathematical operations in your code is one of the most compelling tasks. Thankfully, PHP provides built in support for majority of mathematical functions ranging from random number generation, number to hexadicmal conversion to finding square root of a number. Let’s review some of the most commonly used math functions with the help of a simple example.

sqrt(): used to find square root of a number passed as parameter. For instance, sqrt(144) will return 12.

Log(): used to find log of a number passed as parameter. For instance log(16) will return 2.7725.

pow(): used to raise first parameter to the power of second. For example pow(2,3) will return 8.