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


PHP cos()用法及代碼示例


cos() 函數是預定義的 PHP 函數。它用於返回數字的餘弦。它返回一個介於 -1 和 1 之間的數值,表示角度的餘弦。

用法:

cos(number);
參數 描述 必需/可選
number 指定一個數字 Required

例子1

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

輸出:

Your number is:3
By using 'cos()' function your number is:-0.98999249660045

例子2

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

輸出:

Your number is:-3
By using 'cos()' function your number is:-0.98999249660045

例子3

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

輸出:

Your number is:0
By using 'cos()' function your number is:1

示例 4

<?php
echo "Your number is:M_PI";
echo "<br>"."By using 'cos()' function your number is:".(cos(M_PI));
?>

輸出:

Your number is:M_PI
By using 'cos()' function your number is:-1

例 5

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

輸出:

Your number is 2*M_PI:6.2831853071796
By using 'cos()' function your number is:1






相關用法


注:本文由純淨天空篩選整理自 PHP cos() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。