PHP log() 函数

2025 年 1 月 12 日 | 2 分钟阅读

log() 函数是 PHP 的内置函数,用于查找数字的自然对数或以指定基数的数字的对数。

语法

参数描述必需/可选
数字指定要计算对数的数值。必需
base指定要使用的基数,默认为“e”(自然对数)。可选

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

示例 1

输出

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

示例 2

输出

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

Example3

输出

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

Example4

输出

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

注意:带基数的 LOG() 函数示例。

示例 5

输出

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

示例 6

输出

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

示例 7

输出

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