We already learn about how to create variables and store data or information in it. Now we will learn how mathematics can be done through variables. There are many operator to perform all these function.
We already learn about how to create variables and store data or information in it. Now we will learn how mathematics can be done through variables. There are many operator to perform all these function.PHP Variables Addition
We already learn about how to create variable and store data or information in it. Now we will learn how mathematics can be done through variables. There are many operator to perform all these function. Such as : + , - , % , / , * , = .Let see few examples:
Example 1:
<?php
$a = "10";
$b = "20";
$c = $a + $b;
echo "$a + $b =" . " " . $c;
?>
Here, in this example we use two operator. The first operator is to assign the values in variable and the second operator is to add the value of the variables.
The output of the above example is : 10 + 20 =30.
PHP Variables Subtraction
Example 1:
<?php
$a = "20";
$b = "10";
$c = $a - $b;
echo "$a - $b =" . " " . $c;
?>
Here, in this example we use two operator. The first operator is to assign the values in variable and the second operator is to subtract the value from the variables.
The output of the above example is : 20 - 10 = 10.
PHP Variables Multiplication
Example 1:
<?php
$a = "10";
$b = "20";
$c = $a * $b;
echo "$a * $b =" . " " . $c;
?>
Here, in this example we use two operator. The first operator is to assign the values in variable and the second operator is to multiply the value of the variables.
The output of the above example is : 10 * 20 = 200.
PHP Variables Division
Example 1:
<?php
$a = "200";
$b = "10";
$c = $a / $b;
echo "$a / $b =" . " " . $c;
?>
Here, in this example we use two operator. The first operator is to assign the values in variable and the second operator is to divide the value of the variables.
The output of the above example is : 200 / 20 = 10.