In an exercise I did :
<?php
$initial = '555';
$a = octdec($initial);
echo $a . "\n";
$b = deg2rad($a) . "\n";
echo $b;
$c = cos($b). "\n"; *(line 9)*
echo $c;
and it does show the correct answer, as well as an error:
365
6.3704517697793
0.99619469809175
PHP Notice: A non well formed numeric value encountered in /home/ccuser/workspace/hg2pmf/index.php on line 9
if I change line 9 with : $c = cos(6.3704517697793). "\n";
the message of error disappear. Why can't I use the $
inside the cos()
when in deg2rad()
works perfectly?
CodePudding user response:
The problem is that on this line...
$b = deg2rad($a) . "\n";
You are adding the new line onto the end of the calculated value.
So remove it and your value will be the number you expect...
$b = deg2rad($a);
As a help, I use
declare(strict_types=1);
and I get the error...
Fatal error: Uncaught TypeError: cos(): Argument #1 ($num) must be of type float, string given in which shows how it's changed the value from a number to a string.