Four small ways to improve PHP program running efficiency

Source: Internet
Author: User
1. use i1 to replace ii1. In line with the habit of cc, the efficiency is high. 2. use PHP internal functions as much as possible. Before writing a function, check the manual to see if there are any related functions. 3. try to use a single quotation mark string. The efficiency of a single quotation mark string is higher than that of a double quotation mark string. 4. use foreach instead of while times 1. use I = 1 instead of I = I 1. In line with c/c habits, high efficiency.

2. use PHP internal functions as much as possible. Before writing a function, check the manual to see if there are any related functions.

3. try to use a single quotation mark string. The efficiency of a single quotation mark string is higher than that of a double quotation mark string.

4. use foreach instead of while to traverse the array. When traversing an array, foreach is much more efficient than while loop, and you do not need to call the reset function. The two traversal methods are as follows:

Reset ($ arr );
While (list ($ key, $ value) = each ($ arr )){
Echo "Key: $ key; Value: $ value
N ";
}
Foreach ($ arr as $ key => $ value ){
Echo "Key: $ key; Value: $ value
N ";
}

Related Article

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.