Welcome to Our Free Tutorial!

PHP-Examples of Variables!

Previous Home Next

Concatenation of variables

Option 1:
<?php
$Num1 = 5;
$Num2 = 3;
$Num3 = $Num1 + $Num2;
echo $Num3;
?>
Option 2:
<?php
$Num1 = 5;
$Num2 = 3;
$Num3 = $Num1 + $Num2;
echo "Sum of two number is" . $Num3;
?>
Result:
8
Result:
Sum of two number is 8
Option 3
<?php
$Num1 = 5;
$Num2 = 3;
$Num3 = $Num1 + $Num2;
echo $Num1;
echo " + ";
echo $Num2;
echo " = ";
echo $Num3;
?>
Option 4(Less Code)
<?php
$Num1 = 5;
$Num2 = 3;
$Num3 = $Num1 + $Num2;
echo $Num1 . " + " . $Num2 . " = " . $Num3;
?>
Result: 5+3=8 Result: 5+3=8
All the above example are same but method are difference.
Previous Home Next