Add / Divide Numbers in PHP
문제
I am working on a Facebook App that needs to be able to average three numbers. But, it always return 0 as the answer. Here is my code:
$y = 100;
$n = 250;
$m = 300;
$number = ($y + $n + $m / 3);
echo 'Index: '.$number;
It always displays Index: 0
Any ideas?
해결책
$y = 100;
$n = 250;
$m = 300;
$number = ($y + $n + $m) / 3;
echo 'Index: '.$number;
Also - you missed ;
in the end of the first 3 lines
다른 팁
Your parentheses are grouped wrongly. You should be doing:
$number = ($y + $n + $m) / 3;
Two problems:
You are missing ;
at the end of these lines:
$y = 100
$n = 250
$m = 300
And to /
has higher precedence than +
so you need to do:
$number = ($y + $n + $m) / 3;
제휴하지 않습니다 StackOverflow