在 PHP 中加/除数字

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4084103/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 11:54:12  来源:igfitidea点击:

Add / Divide Numbers in PHP

phpmathechoadddivide

提问by Zac Brown

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:

我正在开发一个需要能够平均三个数字的 Facebook 应用程序。但是,它总是返回 0 作为答案。这是我的代码:

$y = 100;
$n = 250;
$m = 300;
$number = ($y + $n + $m / 3);
echo 'Index: '.$number;

It always displays Index: 0

它总是显示索引:0

Any ideas?

有任何想法吗?

回答by zerkms

$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

另外 - 你错过;了前 3 行的末尾

回答by casablanca

Your parentheses are grouped wrongly. You should be doing:

您的括号分组错误。你应该这样做:

$number = ($y + $n + $m) / 3;

回答by codaddict

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:

并且 to/具有更高的优先级+,您需要这样做:

$number = ($y + $n + $m) / 3;