# Learn PHP

### Operator

Operators are used to perform operations on variables and values.

The basic function of an operator is to do something with the value of a variable. That “something” can be to assign a value, change a value, or compare two or more values.

### PHP Assignment Operators

The assignment operators set the values of variables either by copying the value or copying a reference to a value.

The PHP assignment operators are used with numeric values to write a value to a variable.

The basic assignment operator in PHP is "=". It means that the left operand gets set to the value of the assignment expression on the right.

Operator Name Description
x = y x = y The left operand gets set to the value of the expression on the right
x =& y Reference \$x =& \$y set \$a to reference \$b
x += y x = x + y Addition
x -= y x = x - y Subtraction
x *= y x = x * y Multiplication
x /= y x = x / y Division
x %= y x = x % y Modulus

### Example

```			<?PHP
\$x = 4;
\$x = \$x + 4;

print \$x;
?>
```

### Example

```			<?PHP
\$Count = 0;
\$Count = \$Count + 5;

\$Count = 0;
\$Count += 5;

//prints 13
print(\$a = \$b = 13);
print("<br>\n");

//prints 7
\$Count = 2;
print(\$Count += 5);
print("<br>\n");
?>
```

### Example

```			<?PHP
\$a = 10;
echo \$a;
?>
```

### Example

```			<?PHP
\$a = 20;
\$a += 100;

echo \$a;
?>
```

### Example

```			<?PHP
\$a = 50;
\$a -= 30;

echo \$a;
?>
```

### Example

```			<?PHP
\$x = 10;
\$y = 6;

echo \$x * \$y;
?>
```

### Example

```			<?PHP
\$x = 10;
\$x /= 5;

echo \$x;
?>
```

### Example

```			<?php
\$x = 15;
\$x %= 4;

echo \$x;
?>
```