当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


PHP log()用法及代码示例


log() 函数是内置的php 函数,用于求一个数的自然对数或数以底数的对数。

用法:

log(number,base);
参数 描述 必需/可选
number 指定计算对数的值。 Required
base 要使用的基数,但默认为 'e' Optional

注意:如果输入数字以 Y 为基数(可选),我们将输出为 X 的 LOG。

示例 1

<?php
$num=2;
echo "Your number is:".$num;
echo "<br>"."By using log() function your number is:".log($num);
?>

输出:

Your number is:2
By using log() function your number is:0.69314718055995

例2

<?php
$num=2.7183;
echo "Your number is:".$num;
echo "<br>"."By using log() function your number is:".log($num);
?>

输出:

Your number is:2.7183
By using log() function your number is:1.000006684914

例3

<?php
$num=-1;
echo "Your number is:".$num;
echo "<br>"."By using log() function your number is:".log($num);
?>

输出:

Your number is:-1
By using log() function your number is:NAN

例4

<?php
$num=0;
echo "Your number is:".$num;
echo "<br>"."By using log() function your number is:".log($num);
?>

输出:

Your number is:0
By using log() function your number is:-INF

注:LOG() 带底座的示例。

例5

<?php
echo "Your number is:log(5,2) ";
echo "<br>"."By using log() function your number is:".log(5,2);
?>

输出:

Your number is:log(5,2) 
By using log() function your number is:2.3219280948874

例6

<?php
echo "Your number is:log(5,10) ";
echo "<br>"."By using log() function your number is:".log(5,10);
?>

输出:

Your number is:log(5,10) 
By using log() function your number is:0.69897000433602

例7

<?php
echo "Your number is:log(5,2.7183) ";
echo "<br>"."By using log() function your number is:".log(5,2.7183);
?>

输出:

Your number is:log(5,2.7183) 
By using log() function your number is:1.609427153552






相关用法


注:本文由纯净天空筛选整理自 PHP log() function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。