add two numbers in php

To add two numbers in PHP, you can simply use the plus sign (+) operator.

main.php
$num1 = 5;
$num2 = 10;
$sum = $num1 + $num2;

echo "The sum of $num1 and $num2 is: $sum";
90 chars
6 lines

This will output:

main.php
The sum of 5 and 10 is: 15
27 chars
2 lines

In the code above, we have defined two variables $num1 and $num2 and assigned them the values 5 and 10 respectively. We then used the plus sign (+) operator to add them together and stored the result in $sum. Finally, we used echo to display the result on the screen.

related categories

gistlibby LogSnag