1:57 AM

Assignment Operators

posted under by FR3@K | Edit This
The main assignment operator is = which is used to assing the right side value to the left. It doesn't mean 'equal to' as in maths. It means 'set to' . This operator returns the result of the assignment.

$x=18;

This statement has the value 18 . A better example:

$x= ($y=3) + ($z=$y-1) ;

This statement assigns 3 to $y, substracts 1 from $y and assigns it to $z and then adds them to assign the result to $x . There are some combined assignment operators too:

operator example equivalent

+= $x+=$y $x=$x+$y
-= $x-=$y $x=$x-$y
*= $x*=$y $x=$x*$y
/= $x/=$y $x=$x/$y
%= $x%=$y $x=$x%$y
.= $x.=$y $x=$x.$y

0 comments

Make A Comment
top