PHP log()函数

PHP log()函数

log()函数是PHP内置函数,用于计算一个数的自然对数或以某个基数为底的对数。

语法

log(number,base);
参数 描述 必填/可选
number 指定用于计算对数的值。 必填
base 用于计算对数的底数,默认为’e’。 可选

注意:如果输入的数字具有基数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()与Base的示例。

示例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

Camera课程

Python教程

Java教程

Web教程

数据库教程

图形图像教程

办公软件教程

Linux教程

计算机教程

大数据教程

开发工具教程