$total = 30 - $nr1 / 13 - $nr2 - 6 * $nr3 - 3 I know we learned that in school but what is first (+ or - or * or /), where are the brackets or do I even need them ?
You put brackets to priortizes what should be calculated first. In math though it starts from division, multiplication, subtraction and finally addition. So, here is the order of precedence for these:
You can however override that rule by specifying brackets, for example you might want to have addition calculated first before anything else.
More Info:
[/|*] and equal but lower precedence given to [-|+], in respect to these four operators (where [] denotes some set of operators, and | denotes a separation of that sets elements, indicating only one can be chosen)First partentheses are calculated. Then multiplication and division. Then plus and minus. If you write say ab/c, because multiplication doesn't precede division, nor does division precede multiplication, the computer will calculate it in the order it stands. So it will first calculate ab and then divide that by c.
+symbol to mean division, but that's pretty far-fetched.)