Jump to content

Jumbala102

New Members
  • Posts

    2
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Jumbala102's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Wow, thank you very much for the detailed answer. It's really well explained. Just a last question, though. While I do get that concatenation and additions have the same precedence order and that the way I typed my "print" code made it so it had to convert the string into a number, I just want to know how it figured that the string was equal to 5? Other than that, I'm pretty sure I won't ever be making that kind of mistake in my scripts since I now understand how it works. Thanks again!
  2. 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.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.