您的位置 首页 php

后端开发:PHP代码优化小技巧让你瞬间提升逼格

PHP代码的优化小技巧,我想很多人都有自己的一套,下面分享一些小技巧,希望对大家有所帮助。

1、循环内部不要声明变量,尤其是对象这样的变量。

2、 foreach 效率更高,尽量用foreach代替while和 for循环

3、循环里别用函数

 for($x=0; $x < count($array); $x)
 

//count()函数在外面先计算

4、用i+=1代替i=i+1。符合c/c++的习惯,效率还高。

5、优化Select SQL语句,如果不需要读取所有字段,Select * from尽量改为 select field from,直接写清楚要读取的字段,然后需要注意你的sql是否会引起全表扫描。

6、尽量的少进行文件操作,虽然PHP的文件操作效率也不低的。

7、在可以用PHP内部字符串操作函数的情况下,不要用 正则表达式

 $addr = strtr($addr, "abcd", "efgh");
 $addr = strtr($addr, array('a' => 'e', ));
 

8、在可以用 file _get_contents替代file、fopen、feof、 fgets 等系列方法的情况下,尽量用file_get_contents,因为它的效率高得多。但是要注意file_get_contents在打开一个URL文件时候的PHP版本问题。

9、Apache解析一个PHP脚本的时间要比解析一个静态HTML页面慢2至10倍。尽量多用静态HTML页面,少用脚本。

10、使用选择分支语句,switch case好于使用多个if,else if语句,并且代码更加容易阅读和维护。

11、当echo 字符串 时用逗号代替点 连接符 更快些。echo一种可以把多个字符串当作参数的“函数”。echo是语言结构,不是真正的函数,故把函数加上了双引号。例如:

echo $str1,$str2
 

文章来源:智云一二三科技

文章标题:后端开发:PHP代码优化小技巧让你瞬间提升逼格

文章地址:https://www.zhihuclub.com/80246.shtml

关于作者: 智云科技

热门文章

评论已关闭

34条评论

  1. 50 couon code BFCM51 26 Inch Classic Riding Crop compare at 50, now only 18 coupon code BLACK40 Adjustable Spreader Bar compare at 70, now only 24 coupon code BLACK40 now only 27 coupon code BLACK40 Fetish Fantsy Comfy Hog Tie Wrist and Ankle Cuff Set compare at 80, now only 30 coupon code BLACK40 Over The Door Restraints compare at 90, now only 30 coupon code BLACK40 Sportsheets Under the Bed Bondage Restraint Kit compare at 100 , now only 36 coupon code BLACK40 Liberator Black Label Wedge With Wrist Cuffs, Blindfold Tethers compare at 175, now only 93

  2. It is characterized by single or multiple, sharply demarcated, pruritic, erythematous, nummular plaques

  3. Now running around is a death, it cialis pills for sale cialis pills for sale is best ed supplements they dont want you to know about better to find that stone tablet, maybe the so called first swordsman before and after cialis pills for sale Bai Yin will leave something behind However, just as no drug works on everyone, no drug is 100 safe and these treatments are no exception

  4. , major birth defects , Doody continues. Age of mom at pregnancy or fertility treatment.

  5. 15 ALOGPS logP 0. Any subject that withdrew during the prophylactic phase was considered a failure assumed to have had malaria.

  6. Several studies have found that sesame seed compounds can stimulate the growth of estrogen dependent ER breast cancer cells

  7. A tumor board consisting of members from our multidisciplinary staff meets each week to review patient cases and discuss treatment options

  8. Cerebrospinal fluid fatty acid binding protein 3 is related to dementia development in a population based sample of older adult women followed for 8 years

  9. In certain embodiments, at least one R 4 is methyl; and the carbon to which the methyl group is attached is in the R configuration

  10. Because it can help you to cut fat, increase energy levels, and protect lean muscle mass in a calorie deficit, it s also perfect for using during PCT to protect your gains and allow you to start gently cutting

  11. Breast invasive carcinoma BRCA Level 3 DNA methylation datasets for the JHU USC HumanMethylation450K platform, CpG annotation files, and clinical information were downloaded from the TCGA data portal 20 However, these findings do raise the question of whether ophthalmologic screening might be beneficial in patients who remain on these medications long term

  12. Pretreatment of 9 day old rats for 3 days with human chorionic gonadotropin hCG increases the amount of estradiol secreted by the testis in response to in vivo or in vitro stimulation with follicle stimulating hormone FSH

  13. High dose chemotherapy with hematopoietic stem cells transplantation for metastatic breast cancer

  14. Antihistone antibody Antineutrophil cytoplasmic antibody ANCA panel Complete blood count CBC with differential Comprehensive chemistry panel Urinalysis Alkeran should not be given to nursing mothers and has not been approved for use in pediatric populations

  15. It s a good idea to talk with your healthcare provider in advance if you have specific timelines for pregnancy and delivery Abdul Ghani MA, DeFronzo RA, Norton L

  16. Another very important and potential trigger of Hashimoto s is Borrelia burgdorferi, the bacteria that causes Lyme disease

  17. After hearing the words of the two, Zhao Ling could not help diabetes drugs jabfm laughing

  18. These are sequences that are flanked by two specific 34 base pair sequences, the so called Lox P sites 1 3

  19. timolol and potassium chloride both increase serum potassium The nailbeds often contain caseous exudate

  20. 03 mM D glucose, 4 FAP can present with extraintestinal manifestations such as osteomas, dental abnormalities unerupted teeth, congenital absence of one or more teeth, supernumerary teeth, dentigerous cysts, and odontomas, congenital hypertrophy of the retinal pigment epithelium CHRPE, desmoid tumors, or extracolonic cancers thyroid, liver, bile ducts, central nervous system, see below

  21. The intracellular nature of O Patients receiving anastrozole had a decrease in hot flashes, vaginal bleeding, vaginal discharge, endometrial cancer, venous thromboembolic events and ischemic cerebrovascular events compared with patients receiving Tamoxifeno Farmoz 20 mg Comprimidos tamoxifen citrate

  22. If it is huge, with perfect protection, we cut it into smaller parts within the bag I hate taking drugs to begin with

  23. Endoscopic incision followed by balloon dilation and ureteral stenting is more effective than balloon catheter dilation alone for ureteroenteral anastomotic strictures and UPJ strictures

  24. The migration assay was performed by a transwell assay kit to test the migratory ability of MDA MB 435S cells

网站地图