PHP output Variable Enlargement bracket, what is this writing? Look at the following code:
The code is as follows |
Copy Code |
<?php Header ("content-type:text/html; Charset=utf-8 "); $test = "1 variable 1"; echo "preceded by a String AA". $test. "BB Back string"; echo "preceded by a string AA {$test} bb back string"; ?> |
You can see that the PHP output variable increases the parentheses with the. Operator output variable string effect is the same, summed up the following 3 points to help understand the PHP output variable enlarge the function of bracket {}:
1. The expression {} inside is a variable, the execution is processed according to the variable;
2. Refer to the special inclusion of variables used in strings so that you can reduce the amount of code input by not using the. operator.
3. Prevent the variable name from being linked with the following string.
Report:
The function of the curly braces {} In a string variable:
PHP variable followed by a brace {}, which is filled with numbers, refers to the PHP variable corresponding ordinal number of characters.
For example:
The code is as follows |
|
$str = ' Hello '; echo $str {0}; Output is H echo $str {1}; Output to E |
If you want to check how long a string satisfies, consider replacing the strlen function with this brace {} plus isset, because isset is a language structure and strlen is a function, so using isset is more efficient than using strlen.
For example, to determine whether a string is less than 5 length:
The code is as follows |
|
if (!isset ($str {5})) is better than if (strlen ($STR) < 5). |