PHP pow()函数
pow()是PHP的数学函数。它将第一个数字的值提升到第二个数字的幂次方。
语法
number pow ( number base , numberexp )
参数 | 描述 | 必需/可选 |
---|---|---|
base | 必需。指定要使用的底数。 | 必需 |
exp | 必需。指定指数。 | 必需 |
返回值:返回一个数字(浮点数和整数),其值等于base的exponent次方。
示例1
<?php
num=pow(3, 2);
echo "Your number is = pow (3, 2)".'<br>';
echo "By using sqrt function Your number is : ".num;
?>
输出:
Your number is =pow(3, 2)
By using sqrt function Your number is : 9
示例2
<?php
num=pow(-4, 2);
echo "Your number is = pow (-4, 2)".'<br>';
echo "By using sqrt function Your number is : ".num;
?>
输出:
Your number is = pow (-4, 2)
By using sqrt function Your number is : 16
示例3
<?php
num=pow(-3, -3);
echo "Your number is =pow(-3, -3)".'<br>';
echo "By using sqrt function Your number is : ".num;
?>
输出:
Your number is =pow(-3, -3)
By using sqrt function Your number is : -0.037037037037037
示例4
<?php
num=pow(-3, -3.2);
echo "Your number is =pow(-3, -3.2)".'<br>';
echo "By using sqrt function Your number is : ".num;
?>
输出:
Your number is =pow(-3, -3.2)
By using sqrt function Your number is : NAN
示例5
<?php
for(i=1;i<=5;i++){
echo "The power value of [i] is". "=".pow($i,2)."<br>";
}
?>
输出:
The power value of [1] is=1
The power value of [2] is=4
The power value of [3] is=9
The power value of [4] is=16
The power value of [5] is=25