Tutorial 18: Assignment Operators


Assignment Operators "assign" values from the right argument to the left argument — usually in the form of variables. The basic assignment operator is "=", which assigns the value on the right to the variable on the left. Here is a table of more assignment operators:

Assignment Same as Description
$a += $b $a = $a + $b Addition
$a -= $b $a = $a - $b Subtraction
$a *= $b $a = $a * $b Multiplication
$a /= $b $a = $a / $b Division
$a %= $b $a = $a % $b Modulus
$a .= $b $a = $a . $b Concatenation

Here's an example of how to use one of the above operators:

<?php

	$a = 71;
	$b = 36;
	
	$a -= $b;
	
	echo $a; // Prints 35

?>

Feel free to experiment with the above assignment operators with some PHP using the practice.php page provided in this folder.

Check out the final example
©2025 Brad Hussey