Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
pow() function in PHP
The pow() function in PHP calculates the power of a number by raising the base to the specified exponent. It handles positive, negative, and floating-point values.
Syntax
pow(base, exponent)
Parameters
base − The base number (can be integer or float)
exponent − The exponent to raise the base to (can be integer or float)
Return Value
Returns the result of base raised to the power of exponent. Returns NAN for invalid operations like negative base with fractional exponent.
Example 1: Basic Power Calculation
Calculate 3 raised to the power of 5 −
<?php
echo pow(3, 5);
?>
243
Example 2: Negative Base and Exponent
Using negative values for base and exponent −
<?php
echo pow(-4, 6) . "<br>";
echo pow(-3, -9);
?>
4096 -5.0805263425291E-5
Example 3: Invalid Operation
When a negative base is raised to a fractional exponent, it returns NAN (Not a Number) −
<?php
echo pow(-4, -5.3);
?>
NAN
Conclusion
The pow() function is useful for mathematical calculations involving exponents. Remember that negative bases with fractional exponents result in NAN values.
