PHP expressions
Expressions are the most important constituent elements of PHP. In PHP 3.0, almost everything you write is an expression. The simplest but most precise definition of an expression is "anything with a value". A simple example is constants and variables.
When you write "$a = 5", you assign the value ' 5 ' to the $a. (In this case, ' 5 ' is an shaping constant). In this case, you want to assign $a to a value of 5. So when you write $b = $a, the result you want is $b = 5. That is, $a is an expression with a value of 5. A simple example of a complex expression is a function.
For example, consider the following functions: function foo () {return 5; }
If you think that writing $c = foo () is actually the same as writing $c = 5, then you are right. A function is an expression whose value is the return value. Because Foo () returns 5, the value of the expression ' foo () ' is 5.
The value of PHP is certainly not limited to shaping, and is usually not. PHP supports three types of values: shaping values, floating-point values, and string values. PHP supports two mixed types (non-scalar): Arrays and objects. These two types of values can be assigned to variables or returned from functions.
PHP 3 is an expression-oriented language, so almost everything is an expression.
Consider the example we have discussed, ' $a = 5 '. It is easy to see that there are two values, the value of the shaping constant ' 5 ', and the value of the variable that is also assigned to 5 $a. But there is actually an additional value, which is the value of the assignment statement itself.
The value of the assignment statement itself is the assigned value, in this case 5. In fact, it means not considering what ' $a = 5 ' To do, it is an expression with a value of 5. In this way, write a statement such as ' $b = ($a = 5) ', just like ' $a = 5; $b = 5; ' (There is a semicolon at the end of each statement). Because the order of assignment is right-to-left you can also write ' $b = $a = 5 '.
Another good example of the direction of expression calculation is the addition, the addition and the first minus and then minus. Users of Php/fi and most other languages may be familiar with variable++ and variable--。 This is a self-adding and self-subtraction operation. In Php/fi 2, the statement ' $a + + ' has no value (it is not an expression), so you can neither assign it to it nor use it in any way. PHP 3 turns them into the same expression as in C, which enhances the ability to add and subtract.
Similar to C, there are two types of self-----plus and post-add in PHP 3. The essence of the first plus and the post-addition is the variable self-addition, the function of the variable itself is the same. The difference is the value of the self-added expression. Shape as ' + + $variable ' first add, calculate the value of the variable since the addition (PHP first do the variable to add, and then read its value, it is called ' first Plus '). After adding the shape of ' $variable + + ', the value of the original variable $variable is computed before the self-addition ( PHP does self-add after reading the value of the variable, so it is called ' post-add '.
The most common expression is the comparison expression. This expression evaluates to 0 or 1, which means FALSE or TRUE, respectively.
PHP Support > (greater than), >= (greater than or equal), = = (equals), < (less than) and <= (less than equals). This expression is usually used in conditional execution, such as an IF statement.
The last expression we want to discuss here is a mixed assignment expression. You already know that if you want to add a $a, you can simply write the word ' $a + + ' or ' + + $a '. But what if the value to be increased is greater than 1, such as adding 3 to it? You can write a few more ' $a + + ', but this is obviously not an efficient or receptive approach. Another common way is to write ' $a = $a + 3 '. Calculate the value of ' $a + 3 ' before assigning it back to the $a so that $a adds 3. In PHP 3, you can abbreviate it like in several other languages (for example, C), so that it's clearer and easier to understand. The current variable $a plus 3 can be written as ' $a + = 3 '. The meaning of this sentence is "take out the value of the $a, add it 3, in the $a". This, in addition to making the statement brief and clear, also makes it execute faster. The value of the expression ' $a + = 3 ', as well as a strict assignment statement, is the assigned value. Note: not 3, but the value of the $a plus 3 (which is assigned to $ A). Any double operator can be used for this assignment operation mode, such as ' $a-= 5 ' (variable $a minus 5), ' $b *= 7 ' (Variable $b multiplied by 7), and so on.
Finally, it is worth mentioning the truth value of the expression. Many times (mostly during conditional execution and looping), you don't care about the specific value of an expression, but just notice that it represents true or FALSE (PHP does not have a dedicated Boolean type). PHP uses a Perl-like method to calculate the true value of an expression. Any non-zero value is TRUE, and 0 is FALSE. Be sure to note that the negative zero value is a value of 0 and is considered TRUE! An empty string can be a string "0" for FALSE; The other string is TRUE. For non-quantity values (arrays and objects)-true if its value does not contain any elements that are FALSE.
http://www.bkjia.com/PHPjc/315992.html www.bkjia.com true http://www.bkjia.com/PHPjc/315992.html techarticle The PHP expression expression is the most important constituent element of PHP. In PHP 3.0, almost everything you write is an expression. The simplest but most precise definition of an expression is that there is a value for any East ...