Home Tutorial Php PHP Variables Using Arithmetic Operators

 
 

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

 

Advertisement

Related Tags for PHP Variables Using Arithmetic Operators:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: January 9, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com