# Calculation with Variables

In addition to texts or string, as shown in the first part, you can also store numbers in variables and calculate the result, for example, add, subtract or multiply them.

## Basics

If one assigns a number to a variable, in contrast to the text or string, no quotation marks may be used. You write the number directly into your code.

The number 10 and 5 are now stored in these variables (\$number1 and \$number2).

The adding takes place using +. In the following script you define two numbers and store the sum of the two numbers in the variable \$result:

For the calculation, the numbers do not necessarily have to be stored in variables. You can also write these directly into the mathematical expression. Subsequently, we save a number in the variable \$number and add the value 5 to it.

Here are some more examples:

;

Of course, these results can also be saved again in extra variables.

#### Decrement and increment

To increase the value of a variable by 1 or to reduce it by 1, there is a simple trick:

You can also lowering a number by placing double minus sign (--) in front of the variables:

If a double plus sign (++) is appended to the variable name (a number variable), the content of this variable, i.e., the number, is incremented, or increased by 1. On the other hand, if double minus signs (--) is used, the value is decremented, that is, decreased by 1.

## Shorthand for assignments

The following script increases the value of defined variable by the number 10:

Since programmers always want the quickly one, PHP still has a shorthand that does exactly the same:

+= Increases the value of the variable \$num by the number 10. Of course, you can also write -=, *= or /= to subtract, multiply or divide values.

## Floating point numbers

In PHP, you can also define a floating number by using a dot sign instead of commas. The mathematical operations remain the same.