How to do Math in PHP

  1. In addition to Variables in PHP today we are going to talk about Math
  2. Yes, you can do calculations in PHP similar to what you do on your calculator
  3. Open your code editor and open a new file.
  4. Open an HTML, HEAD, and PHP Tags
  5. Between the PHP tags,
  6. You can do additions, subtractions, division, and multiplications
  7. For every function, use echo and then simply add, multiply or subtract. 
  8. Syntax for functions – (+ for addition), (- for subtraction), (* for multiplication) and (/ for division)
  9. We can also do calculations with multiple functions such as “echo 45 + 34 * 45 / 421 – 45;”
  10. I would like to also share with you on the order of operations. Please remember that multiplication and division go before addition and subtraction.
  11. For example – echo 5 + 5 * 10 will show as 55 and not 100 unless you place 5+5 in prentices like (5 + 5) * 10
  12. Also – You can save numbers as variables and use them for calculations. For example – $number1 = 12; and $number2 = 24;.  Echo $number1 + $number2;

One Reply to “How to do Math in PHP”

Leave a Reply

Your email address will not be published. Required fields are marked *