Home Tutorial Php PHP Variables Using Arithmetic Operators

 
 

PHP Variables Using Arithmetic Operators
Posted on: January 9, 2010 at 12:00 AM
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.

 

Related Tags for PHP Variables Using Arithmetic Operators:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.