Orignal source:http://codingvilla.com/add-subtract-divide-multiply-integers-php-single-article-567.aspx

Integer Data Type:

In PHP integer is single-value type. Integers are whole numbers. Its range varies according to your platform. But you can use any number from -

2,147,483,648to+2,147,483,647. Integer can be written in decimal, octal and hexadecimal.

We can represent Decimal without zero, octal with a leading 0 and a sequence of digits from 0 to 7, hexadecimal with 0-9 digits and A-F alphabets.

For example:

1998 (Decimal)

0755 (Octal)

0xFF(hexadecimal)

Add integer in PHP:

To add integers in PHP we take two variables and assign them with integer values then by sum operator add them and store result in another variable and result also an integer value.

Code:

<?php

$a = 2;

$b = 4;

echo "<P>Original value of \$a is $a and \$b is $b</P>";

$c = $a + $b;

echo "<P>Add \$a and \$b and got $c</P>";

?>

This is simple code to add integer values in PHP.

Subtract integer in PHP:

To subtract integers in PHP we take two variables and assign them with integer values then by Subtraction operator Subtract them and store result in another variable and result also an integer value.

Code:

<?php

$a = 12;

$b = 4;

echo "<P>Original value of \$a is $a and \$b is $b</P>";

$c = $a - $b;

echo "<P>Subract \$a and \$b and got $c</P>";

?>

This is simple code to subtract integer values in PHP.

Multiply integer in PHP:

To multiply integers in PHP we take two variables and assign them with integer values then by multiplication operator multiply them and store result in another variable and result also an integer value or long value.

Code:

<?php

$a = 12;

$b = 4;

echo "<P>Original value of \$a is $a and \$b is $b</P>";

$c = $a * $b;

echo "<P>Multiply \$a and \$b and got $c</P>";

?>

This is simple code to multiply integer values in PHP.

Divide integer in PHP:

To divide integers in PHP we take two variables and assign them with integer values then by division operator divide them and store result in another variable and result also an integer value or float value.

Code:

<?php

$a = 12;

$b = 4;

echo "<P>Original value of \$a is $a and \$b is $b</P>";

$c = $a /$b;

echo "<P>Divide \$a and \$b and got $c</P>";

?>

This is simple code to divide integer values in PHP.

This simple article tells that how we can to add - subtract - divide - multiply integers in PHP

# Add / subtract / divide / multiply integers in PHP

by anonymous