Php super-long string link output performance problems ~~~

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.