PHP Operators
Write a PHP program to add two numbers
Description: Write a PHP program to find the sum (addition) of two numbers.
Rules and hints:
PHP program to add two numbers
<?php
$first = 15;
$second = 10;
$sum = $first + $second;
echo "Result: " . $sum;
?>
Output:
Tutorials Class - Output Window
Result: 25
How it works
- The two numbers are stored in $first and $second.
- The result of the addition is stored in $sum and printed.
Try this too
- Change the program to subtract, multiply and divide the numbers.
- Take the numbers from an HTML form using
$_POST. See PHP Forms Handling.