When you learn PHP for the first time, understanding how the PHP interpreter understands what you write can be a challenge. And this is all the more true if PHP is your first programming language. Here we undertake to understand how PHP understands almost everything you write as an expression or a combination of expressions.
PHP expressions are a lot like variables in algebra. You may recall in the equation
z = x + yz is an expression. But in PHP, the concept of expressions is more robust. Not only are z, x, and y expressions but the phrase 'x+y' is an expression, too. If you have a function that takes x and y as arguments and returns a value, that function returns an expression, the results of the PHP function.
But there are more expressions in the above equation than the individual parts. If we put it in PHP, we would get the following line:
$z = $x + $y;As mentioned above, $z, $x, and $y are all expressions of value. But even the very assignment of value to $z is an expression. If $x is 3 and $y is 2, then the above assignment is more than just $z = 5. It further evaluates to 5 based on the assignment alone. This is seen in the following PHP program:
<?phpAnd the outcome of each echo statement will be 5.
$x = 3;
$y = 2;
$z = $x + $y;
echo $z;
echo $z = $x + $y;
echo $x + $y;
?>
PHP Tutorials:
Apache Tutorials:
Install Apache | Basic Configuration | Apache In-Depth |
Recommend Web Hosting | Customising Apache | PHP Hosting |
Install MySQL | Basic MySQL Configuration | MySQL Configuration In-Depth |