Adding variables values

To add a two variables values in PHP, the plus symbol (+) is used. Open from the previous page (variables.php), try changing the full stop to a plus symbol. Run the code, and see what happens.). Try the following script:

<?PHP

$first_string = “This is my first string”;

$second_string=”This is my second string”;

print($first_string+$second_string);

?>

Above code with print “0”. Please find below a script for adding numbers:

<?PHP

$first_number = 10;

$second_number = 20;

print($first_number+$second_number);

?>

In the above script, we are adding the contents of one variable to the contents of another.

The addition to the right of the equals sign gets calculated first ($first_number + $second_number). The total of the addition is then stored in the variable to the left of the equals sign ($sum_total =). Try the following script:

<?PHP

$first_number = 10;

$second_number = 20;

$sum_total = $first_number+$second_number

print($sum_total);

?>

You can, of course, add up more than two numbers.