當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。