开发者

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;
$num开发者_如何学JAVAber = ($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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜