Hi, I'm just starting PHP and I ran into a simple problem (that I can fix), but I just want to understand why my first approach doesn't work.
I was testing multiplications and additions and the result I got was unexpected.
Here is the code that doesn't work:
<?php
$number1 = 5;
$number2 = 10;
print $number1." multiplied by ".$number2." + 1000 = ".$number1*$number2+1000;
?>
Obviously, what I want as a result when I'm displaying the page is: "5 multiplied by 10 + 1000 = 1050"
What I get: "1005". That's right, nothing else. On top of getting an erroneous answer, the sentence that's supposed to display right before the equation doesn't display at all.
It's even worse if I switch it around like that:
print $number1." multiplied by ".$number2." + 1000 = ".1000+$number1*$number2;
I get an error message and nothing displays.
The obvious solution works: using a parenthesis at the beginning and at the end of the equation, which I should do regardless, but still, it's bugging me and since I just started learning PHP today, I want to understand how the code is compiled / interpreted so I don't make stupid mistakes like this one.
Thanks in advance for the replies.