05-20-2016, 09:57 PM
The basic assignment operator (=) assigns a value to a variable. The lefthand operand is always a variable. The righthand operand can be any expression?any simple literal, variable, or complex expression. The righthand operand's value is stored in the variable named by the lefthand operand.
Because all operators are required to return a value, the assignment operator returns the value assigned to the variable. For example, the expression $a = 5 not only assigns 5 to $a, but also behaves as the value 5 if used in a larger expression. Consider the following expressions:
The expression $a = $b is evaluated first, because of the parentheses. Now, both $a and $b have thesame value, 10. Finally, $c is assigned the result of the expression $a = $b, which is the value assignedto the lefhand operand (in this case, $a). When the full expression is done evaluating, all three variablescontain the same value, 10.
Because all operators are required to return a value, the assignment operator returns the value assigned to the variable. For example, the expression $a = 5 not only assigns 5 to $a, but also behaves as the value 5 if used in a larger expression. Consider the following expressions:
Quote:$a = 5;
$b = 10;
$c = ($a = $b);
The expression $a = $b is evaluated first, because of the parentheses. Now, both $a and $b have thesame value, 10. Finally, $c is assigned the result of the expression $a = $b, which is the value assignedto the lefhand operand (in this case, $a). When the full expression is done evaluating, all three variablescontain the same value, 10.