Return is more efficient than global when an array is passed, for example: functionuserloginfo ($ usertemp) {$ detail = explode ("", $ usertemp); return $ detail ;} $ login = userloginfo ($ userdb); than functionuser
Return is more efficient than global when an array is passed, 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
II. (this code is used to obtain the URL corresponding to the program directory and is recommended for applications)
$ 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. it is more efficient to determine the application of the constant value in the cycle.
$ A = 2; $ B = 2;
For example
If ($ a ==$ B) $ c = $;
Ratio
If ($ a ===$ B) $ c = $;
Efficient
4. when querying mysql, try to use where in with less limit
Limit queries the first few records of multiple records, which is fast, but the query speed is slow
Application in. the query of persistent records is very fast. the first running of non-persistent records will be a little slower, but it will be faster later!
V. NT Server data control is less stable than unix/linux
6. try to apply ob_start () to the application before output. it can accelerate the output speed and be used in NT or nuli/linux. for unlix servers, if ob_start ('OB _ gzhandler') is used '); higher output efficiency
7. apply if ($ a = his value) whenever possible during the determination and apply if (empty ($ a) whenever possible. as a result, the program runs faster.
8. application time not supported! = Equivalent to <> efficiency
9. Personal experience $ a = '000000'; efficiency is quite different from $ a = '000000 '.
10. Application of standardized SQL statements will facilitate MySQL parsing
11. Application
If ($ online ){
$ Online1 = $ online;
Setcookie ('online1', $ online, $ cookietime, $ ckpath, $ ckdomain, $ secure );
}
COOKIE will take effect immediately
Application
If ($ online)
Setcookie ('online1', $ online, $ cookietime, $ ckpath, $ ckdomain, $ secure );
The COOKIE needs to be refreshed again to take effect.