In the last lesson we learned how to define the variables and used it in our code.
PHP Step by step - Variables
OK now we will learn how to make some calculations in php
if we put the first var with the value 10 and the other with the value 20 and print the sum of them like
$var1 = 10;
$var2 = 20;
$total = $var1 + $var2;
print( 'The two variables added together = ' . $total );
in $total var we put the + between the two vars to calculate the two vars and in print function we put the text between ' ' or u can put them between " " and separate between the statement and the $total var by . and in line end put ;
Add a third variable to your code. Assign a value of 30 to your new variable. Put the sum total of all three variables into the variable called $sum_total. Use concatenation to display the results. (In other words, add up 10, 20, and 30!)
You don't have to use variable names to add up. You can do this:
print (10 + 20 + 30);
Or even this:
$number = 10;
print ($number + 30);
But the point is the same - use the plus symbol (+) to add up.