The output variable in php adds brackets. Php output variables increase brackets. what is the writing method? See the following code: Copy the code as follows? Phpheader (Content-Type: texthtml; charsetutf-8); $ test1 variable 1; echo front php output variable increase brackets, what is this writing? See the following code:
The code is as follows: |
|
Header ("Content-Type: text/html; charset = utf-8 "); $ Test = "1 variable 1 "; // Echo "there is a string aa". $ test. "bb string "; Echo "there are strings following aa {$ test} bb "; ?> |
We can see that the php output variable adding brackets is the same as using the. operator to output the variable string, and summarize the following three points to help understand the php output variable adding brackets:
1. the variable in {} is processed according to the variable during execution;
2. use special methods to reference variables in strings, so that you do not use the. operator to reduce the input of code;
3. prevent variable names and strings from being connected together.
Appendix:
Function of braces {} in string variables:
Add a braces {} next to the PHP variable, and fill in a number, which is the character corresponding to the PHP variable serial number.
For example:
The code is as follows: |
|
$ Str = 'hello '; Echo $ str {0}; // The output is h. Echo $ str {1}; // The output is e. |
If you want to check whether the length of a string is sufficient, consider replacing the strlen function with this braces {} and isset, because isset is a language structure and strlen is a function, therefore, using isset is more efficient than using strlen.
For example, to determine whether the length of a string is less than 5:
The code is as follows: |
|
If (! Isset ($ str {5}) is better than if (strlen ($ str) <5. |
Why? See the following code: the code is as follows? Php header (Content-Type: text/html; charset = utf-8); $ test = 1 variable 1; // echo is preceded...