Perform calculations
  1. Create a new script with this code:

    <?php

    $var1 = 5;
    $var2 = 2;

    $answer = $var1 + $var2 ;

    print "$var1 plus $var2 equals $answer.";

    ?>
  2. Save the script as add.php in the PHPSCRIPTS folder.

    Here's what the relevant lines in this script do:
  • $answer = $var1 + $var2 ;

    Adds the variables $var1 and $var2 together, then assigns the sum to a variable called $answer.

    Since $var1 is 5, and $var2 is 2, $answer has a value of 7.

  1. Upload add.php to the PHPSCRIPTS directory on the Web server.

Want ad-free tutorials like these for classroom use? Get them at Visilearn.com.