Assignment Operators
Assignment operators are used to perform operations and assign values in variables. Basic assignment operators used in php are as follows:
= Operator
<?php $a=5; echo $a; // outputs 5 ?>+= Operator
<?php $a=5; $a+=6; echo $a; // outputs 11 ?>$a+=6 is same as $a=$a+6.
-= Operator
<?php $a=5; $a-=4; echo $a; // outputs 1 ?>$a-=6 is same as $a=$a-6.
*= Operator
<?php $a=5; $a*=6; echo $a; // outputs 30 ?>$a*=6 is same as $a=$a*6.
/= Operator
<?php $a=5; $a/=2; echo $a; // outputs 2.5 ?>$a/=6 is same as $a=$a/6.
.= Operator
<?php $a=5; $b=6; $a.=$b; echo $a; // outputs 56 ?>$a.=$b is same as $a=$a.$b.
%= Operator
<?php $a=5; $a%=2; echo $a; // outputs 1 ?>$a%=6 is same as $a=$a%6.
This is all for assignment operators, feel free to comment and ask any questions that you may have.
Previous Lesson --- Next Lesson
No comments:
Post a Comment