Add / Divide Numbers in PHP
33,796
Solution 1
$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
Solution 2
Your parentheses are grouped wrongly. You should be doing:
$number = ($y + $n + $m) / 3;
Solution 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;
Author by
Zac Brown
Computer geek, entrepreneur, soccer freak, Founder & CEO TeraTech Mobile, avid cyclist. That is all.
Updated on November 03, 2020Comments
-
Zac Brown over 3 years
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?