PHP optimization summary 1. if the class method can be defined as static, it should be defined as static as much as possible, and its speed will be increased by nearly four times.
2. try to use absolute paths when using include files, because it avoids PHP's speed of searching for files in include_path.
3. preg_replace is faster than str_replace, and the execution speed of strtr is nearly four times faster than that of preg_replace.
4. $ row ['id'] is 7 times faster than $ row [id.
5. use foreach instead of for ($ x = 0; $ x <count ($ array); $ x) because count ($ array) is executed every time.
6. use multiple echo parameters (comma instead of period) to replace string connection. For example, echo $ str1, $ str2
7. Using the select branch statement is better than using multiple if and else if statements.
8. replace double quotation marks with single quotes to include strings. this will be faster. Because PHP searches for variables in strings enclosed by double quotation marks, but not in single quotes.
9. do not replace objects with arrays instead of OO.
10. method calling seems to have nothing to do with the number of methods defined in the class, because I have added 10 methods before and after the test method, but the performance has not changed. Therefore, the size of the class file does not affect the performance. when you need it, you can always break down the code into methods.
It is best to make these summaries a habit of coding.