Assignment Operators in PHP

Operator     Example                 Action
+=               $a += 3;               Changes the value of a variable
                                                 variable  to the current value
                                                 plus the value on the right side.

-=                $a -= 3;                Changes the value of a variable
                                                 to the current value minus the
                                                 value on the right side.

.=                 $a .= “string”;       Concatenates (adds on to) 
                                                                                                      the value on the right side with
                                                                                                      the current value.
Example:
<HTML>
<HEAD>
<TITLE>Using Assignment Operators</TITLE>
</HEAD>
<BODY>
<?
$origVar = 100;
echo “<P>Original value is $origVar</P>”;
$origVar += 25;
echo “<P>Added a value, now it’s $origVar</P>”;
$origVar -= 12;
echo “<P>Subtracted a value, now it’s $origVar</P>”;
$origVar .= ” chickens”;
echo “<P>Final answer: $origVar</P>”;
?>
</BODY>
</HTML>

About the author

Being the CEO and Founder of ClecoTech International, Mr. Ashish Prajapati is dedicated towards his aim of mentoring young startups into a full-fledged businesses. He is helping startups from America, Europe, India, and various other countries through proper guidance and the use of latest technologies to develop their innovation and ideas into definite realities.

Leave a Reply

Your email address will not be published. Required fields are marked *