Home > Backend Development > PHP Tutorial > Summary of php code writing habits optimization_PHP tutorial

Summary of php code writing habits optimization_PHP tutorial

WBOY
Release: 2016-07-21 15:05:00
Original
764 people have browsed it

(1) Using static static method is 4 times faster than ordinary method
(2) echo output is faster than print
(3) Use connection characters instead.
(4) Take out the maximum before looping value, instead of taking the value in the loop
The correct method
$max = count($array);
for ($i=0;$i<$max;$ i++) {
echo $i;
}
Wrong method
for ($i=0;$i echo $i;
}
(5) Use unset to release the given variable
(6) Includes and requires include the file using the full path
(7) Use strncasecmp, strpbrk and stripos instead regex
(8) Use switch instead of if else statement
(9) Suppress error characters @ performance is very low
(10) Remember to close unnecessary database connections at any time
(11) $row ['id'] is 7 times faster than $row[id]
(12) Adding a global variable is 2 times slower than adding a local variable
(13) Use single quotes instead of double quotes to quote characters
(14) Using HTML is 2-20 times faster than PHP scripts
(15) Using PHP caching can speed up performance by 25%-100%
(16) $++ is slower than ++$i
( 17) Don’t overuse OOP, use it in moderation
(18) Try to use PHP built-in functions

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327732.htmlTechArticle (1) Using static static method is 4 times faster than ordinary method (2) echo output is faster than print (3) Use the connecting character, instead. (4) Take out the maximum value before looping, not inside the loop...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template