PHP Value Assignment Operators

Here we can learn about the operators used for assigning values in PHP.

Operator “=”
Usage Sample program

<?php
$x = 10;
$y = $x;
?>

Operator “+=”
x +=y is same as x = x + y
Usage Sample program

<?php
$x = 10;
$y = 20;
$x += $y;
echo $x ;
?>

Output of this PHP program will be :
30

Operator “-=”
x -=y is same as x = x – y
Usage Sample program

<?php
$x = 30;
$y = 20;
$x -= $y;
echo $x ;
?>

Output of this PHP program will be :
10

Operator “*=”
x *=y is same as x = x * y
Usage Sample program

<?php
$x = 5;
$y = 6;
$x *= $y;
echo $x ;
?>

Output of this PHP program will be :
30

Operator “/=”
x /=y is same as x = x / y
Usage Sample program

<?php
$x = 10;
$y = 5;
$x /= $y;
echo $x ;
?>

Output of this PHP program will be :
2

Operator “.=”
x .=y is same as x = x . y ( Concatenation operation )
Usage Sample program

<?php
$x = "Syam";
$y = "Here";
$x .= $y;
echo $x ;
?>

Output of this PHP program will be :
Syam Here

Operator “%=”
x %=y is same as x = x % y ( Division Remainder )
Usage Sample program

<?php
$x = 10;
$y = 3;
$x %= $y;
echo $x ;
?>

Output of this PHP program will be :
1

Share
Share
Share