1. when passing an array in a function: Using return is more efficient than using global, for example, functionuserloginfo ($ usertemp) {$ detailexplode (& quot; | & quot;, $ usertemp); return
1. when passing an array in a function:Using return is more efficient than using global, for example
- Function userloginfo ($ usertemp ){
- $ Detail = explode ("|", $ usertemp );
- Return $ detail;
- }
- $ Login = userloginfo ($ userdb );
Ratio
- Function userloginfo ($ usertemp ){
- Global $ detail;
- $ Detail = explode ("|", $ usertemp );
- }
- Userloginfo ($ userdb );
Efficient
2. (this code is used to obtain the URL corresponding to the program directory, which is recommended)
- $ Urlarray = explode ('/', $ HTTP_SERVER_VARS ['request _ URI ']);
- $ Urlcount = count ($ urlarray); unset ($ urlarray [$ urlcount-1]);
- $ Ofstarurl = 'http: // '. $ HTTP_SERVER_VARS ['http _ host']. implode ('/', $ urlarray );
Code comparison
- $ Pre_urlarray = explode ('/', $ HTTP_SERVER_VARS ['http _ referer']);
- $ Pre_url = array_pop ($ pre_urlarray );
Efficient
3. in the cycle, it is more efficient to use constant to determine the value.
- $ A = 2; $ B = 2;
For example
- If ($ a ==$ B) $ c = $;
- Ratio
- If ($ a ===$ B) $ c = $;
- Efficient
4. use where in to use less limit for mysql queries.
The speed of limit to query the first few records of multiple records is very fast, but it will be slow to query the first few records, using in. it is very fast to query the continuity record. the first running of the non-continuity record will be a little slower, but it will be faster later!
5. the data operation stability of the NT Server is less than that of unix/linux
6. use ob_start () whenever possible before output ();It can accelerate the output speed and is applicable to NT or nuli/linux. for unlix servers, if ob_start ('OB _ gzhandler') is used, the output efficiency will be higher.
7. try to use if ($ a = his value) if (empty ($ a) if it is negative )),Because the program runs faster
8. when not supported! = Equivalent to <> efficiency
9. in my personal experience, the efficiency of using $ a = "11111111111111"; is equivalent to that of $ a = '000000 '.It is not as different as the book says.
10. using standard SQL statements will facilitate MySQL parsing.
11. use
- If ($ online ){
- $ Online1 = $ online;
- Setcookie ('online1', $ online, $ cookietime, $ ckpath, $ ckdomain, $ secure );
- }
The COOKIE will take effect immediately.