Nuances of Working with the Assignment Operation in PHP
Now we will analyze some nuances of working with the assignment operation.
Look at the following example:
<?php
$num = 1; // declare the variable $num and assign the value 1 to it
$num = $num + 2; // assign to $num itself plus 2
echo $num; // will output 3
?>
Without running the code, determine what will be displayed on the screen:
<?php
$num = 1;
$num = $num + 1;
$num = $num + 1;
echo $num;
?>
Without running the code, determine what will be displayed on the screen:
<?php
$num = 1;
$num = $num + 2;
$num = $num + 3;
echo $num;
?>