Php expressions are the most important component of PHP. In PHP3.0, almost everything you write is an expression. The simplest but precise definition of an expression is & quot; anything with a value & quot ;. A simple example is constants and variables. When you write & quot; $ a5 & quot;, you assign a value of 5 to $. (In this case, 5 is an integer constant ). Here, your php expression
Expressions are the most important component of PHP. In PHP 3.0, almost everything you write is an expression. The simplest but 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 $ '. (In this case, '5' is an integer constant ). Here, you want to assign $ a to 5. So when you write $ B = $ a, the expected result is $ B = 5. $ A is an expression with a value of 5. A simple example of a complex expression is a function.
For example, consider the following function: 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 returned. Because foo () returns 5, the value of 'foo () 'is 5.
PHP values are not limited to integer values, and are generally not. PHP supports three types of values: integer value, floating point value, and string value. PHP supports two types of mixing (non-scalar): Array and object. 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 here, the value of the integer constant '5', and the value of the variable $ a which is also assigned as 5. However, there is actually an additional value, that is, the value of the value assignment statement itself.
The value of the value assignment statement is the value assigned. In this example, the value is 5. in fact, it means not to consider what '$ a = 5' is to do. it is an expression with a value of 5. In this way, write a statement such as '$ B = ($ a = 5)', like '$ a = 5; $ B = 5; '(There is a semicolon at the end of each statement ). Because the assignment order is from right to left, you can also write it as '$ B = $ a = 5 '.
Another good example of the direction of expression calculation is to add, add, subtract, and then subtract first. PHP/FI and users in most other languages may be familiar with variable ++ and variable --. This is an auto-increment and auto-increment operation. In PHP/FI 2, the '$ a ++' statement has no value (it is not an expression), so you can neither assign a value to it nor use it in any way. PHP 3 converts them into the same expressions as C, thus enhancing the self-addition and auto-subtraction operations.
Similar to C, PHP 3 also has two types of auto-increment ---- add first and then add. In essence, the first addition and the second addition are variable auto-addition, which have the same effect on the variable itself. The difference is the value of the self-added expression. Like '+ + $ variable', add the variable first, and calculate the value of the variable after auto-addition (PHP first performs variable auto-addition and then reads its value, which is also called 'Add first '). for example, after adding '$ variable + +', the original variable $ variable value is calculated before auto-addition (PHP then performs auto-addition after reading the variable value, so it is called 'postadd ').
The most common expression is a comparison expression. The calculated result of this expression is 0 or 1, which means FALSE or TRUE, respectively.
PHP supports> (greater than),> = (greater than or equal to), = (equal to), <(less than), and <= (less than or equal ). This expression is usually used in conditional execution, such as the IF statement.
The expression we will discuss at the end is a mixed value assignment expression. You already know that to add $ a plus one, you can simply say '$ a ++' or '+ + $ '. But what if the value to be added is greater than 1, for example, adding 3 to it? You can write '$ a ++' multiple times, but this is obviously not an efficient or acceptable method. Another common method is to write '$ a = $ a + 3 '. Calculate the value of '$ a + 3' and return it to $ a. Then, 3 is added to $. In PHP 3, you can simply name it like in several other languages (such as C), so it is clearer and easier to understand. You can write the current variable $ a Plus 3 as '$ a + = 3 '. This sentence means "getting the value of $ a, adding it to 3, and assigning it to $ ". This not only makes the statement short and clear, but also makes it run faster. The value of '$ a + = 3' is assigned, just like a strict value assignment statement. Note: instead of 3, it is the value of $ a plus 3 (this is assigned to $ ). Any double operators can be used in this assignment operation mode, such as '$ a-= 5' (variable $ a minus 5 ), '$ B * = 7' (variable $ B multiplied by 7), and so on.
It is worth mentioning the true value of the expression. Many times (mainly during conditional execution and loop), you don't care about the specific value of the expression, but pay attention to whether it represents TRUE or FALSE (PHP does not have a dedicated Boolean type ). In PHP, the perl-like method is used to calculate the true value of an expression. Any non-zero value is TRUE, and zero is FALSE. Please note that the negative zero value is a non-zero value and is considered TRUE! The value of null string "0" is FALSE, and the value of other strings is TRUE. For non-quantity values (arrays and objects)-if its value does not contain any element, it is FALSE; otherwise, it is TRUE.