Several methods to improve php sequence running efficiency
Source: Internet
Author: User
1. replace I = I + 1 with I + = 1. In line with the c/c ++ habits, the efficiency is high. 2. apply 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 apply single quotes. 1. replace I = I 1 with I = 1. In line with c/c habits, high efficiency.
2. apply PHP internal functions as much as possible. Before writing a function, check the manual to see if there are any related functions.
3. use single quotes as much as possible. 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 ';
}
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