PHP 中的数字加/除

发布于 2024-09-30 12:59:08 字数 216 浏览 1 评论 0原文

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

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

它总是显示 Index: 0

有什么想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦初启 2024-10-07 12:59:08
$y = 100;
$n = 250;
$m = 300;
$number = ($y + $n + $m) / 3;
echo 'Index: '.$number;

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

$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

蒲公英的约定 2024-10-07 12:59:08

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

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

Your parentheses are grouped wrongly. You should be doing:

$number = ($y + $n + $m) / 3;
戴着白色围巾的女孩 2024-10-07 12:59:08

两个问题:

您在这些行的末尾缺少 ;

$y = 100
$n = 250
$m = 300

并且 / 的优先级高于 + 因此您需要执行以下操作:

$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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文