PHP improves programming efficiency (ii)

Source: Internet
Author: User
1, the Str_replace function is faster than the Preg_replace function, but the efficiency of the STRTR function is four times times the Str_replace function.

2, if a string substitution function, can accept an array or character as a parameter, and the parameter length is not too long, then you can consider an extra piece of replacement code, so that each pass argument is a character, rather than write a line of code to accept the array as the query and replace parameters.

3. Use the Select Branch statement: The switch case is better than using more than one if,else if statement.

4. Masking error messages with @ is extremely inefficient and extremely inefficient.

5, open the Apache mod_deflate module, can improve the browsing speed of the page.

6, the database connection should be turned off when used, do not use long connection.

7. Error messages are costly.

8, increment the local variable in the method, the speed is the quickest. is almost equivalent to the speed at which local variables are called in the function.

9, incrementing a global variable is twice times slower than incrementing a local variable.

10, incrementing an object property (such as: $this->prop++) is 3 times times slower than incrementing a local variable.

  • 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.