How to Add Two Numbers Using PHP

104 30
    • 1). Create a new PHP page in a Web design application or text editor.

    • 2). Add the following code to the page, between the "<body>" and "</body>" HTML tags:

      <?php

      $a = 10;

      $b = 15;

      $total = $a + $b;

      echo "A + B = " . $total;

      ?>

      First, two variables are assigned with the values 10 and 15. The variables are then added using the addition operator -- "+" -- and the result assigned to a variable named $total. The result of the calculation is then displayed to the user using the "echo" command.

    • 3). Save the page and then upload to your PHP Web server. Open the page in a Web browser and you will see the following displayed:

      A + B = 25

      This demonstrates the two numbers have been correctly added together.

Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time

Leave A Reply

Your email address will not be published.