In a loop, when echo links and outputs some variables and strings, how can the output performance be higher? 1. use $ html & quot; variables and ". and then output {code ...} 2. use one echo + multiple commas to output {code ...} 3. multiple echo outputs {code ...} in a loop, when echo links and outputs some variables and strings, how can the output performance be higher?
1. Use$html=""
Variable and“.”
Splicing and Output
$html = "";foreach() { $html .= ".....";}echo $html;
2. output with one echo + multiple commas
foreach() { echo "...", "....", "..."; if () { echo "...." }}
3. Multiple echo outputs
foreach() { echo "..."; echo "..."; echo "..."; echo "..."; echo "...";}
Reply content:
In a loop, when echo links and outputs some variables and strings, how can the output performance be higher?
1. Use$html=""
Variable and“.”
Splicing and Output
$html = "";foreach() { $html .= ".....";}echo $html;
2. output with one echo + multiple commas
foreach() { echo "...", "....", "..."; if () { echo "...." }}
3. Multiple echo outputs
foreach() { echo "..."; echo "..."; echo "..."; echo "..."; echo "...";}
To output strings faster, you must understand the process of string output. First, the zend engine obtains the echo statement and starts to detect the content to be output until the end of the semicolon. Then, it converts all the variables in the content into strings, concatenates them, and outputs them.
To output a string faster, start with the above output process. On the one hand, the variable is converted to the string speed, on the other hand, the string is removed, and output directly without splicing.
Hope to help you .?
Use commas (,) to echo multiple times.
References
As long as the output performance is the same, it is better to find a way to cache the content that can be cached on the client, so that you do not need to worry about performance.
I suggest you replace double quotation marks with single quotation marks, because php will parse the variables in double quotation marks for test.