PHP cos() 函数
cos() 函数是预定义的 PHP 函数。它用于返回一个数的余弦值。它返回一个在 -1 和 1 之间的数值,表示角度的余弦值。
语法
cos(number);
Parameter | Description | Required/Optional |
---|---|---|
number | Specify a 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