Adding / Small exercise

Now that you learned how to declare variables and concatenate them let’s make a simple exercise and use what we learned in the last tutorials to generate a message that the server will output to the browser:

For this exercise we will need a total of four variables, three of type int/float (whole number/decimal number) and one of type string (text). Two variables will hold numbers, one will hold the sum of them and the last one will hold our text. The requirement of this exercise is to output the text concatenated with the sum:

<?php

 $numberOne = 10;

$numberTwo = 15;

$age = $numberOne + $numberTwo;

$text = “My age is”;

echo $text.$age;

?>

I hope that know you have a better understanding about how the addition and concatenation works in php.

Note: Every other mathematical operation works in the exact same way as the addition therefore i will not make tutorials for every operation but if you think i should it just say it in a comment or contact me and tell me to do it and i will do it.

Cheers.

 

Leave a comment