foreach是对数组副本进行操作(通过拷贝数组),而while则通过移动数组内部指标进行操作,一般逻辑下认为,while应该比
foreach快(因为foreach在开始执行的时候首先把数组复制进去,而while直接移动内部指标。),但结果刚刚相反。
在循环里进行的是数组“读”操作,则foreach比while快:
网:http://www.veryhuo.com/
foreach ($array as $value) {
echo $value;
}
while (list($key) = each($array)) {
echo $array[$key];
}
在循环里进行的是数组“写”操作,则while比foreach快:
foreach ($array as $key => $value) {
echo $array[$key] = $value . ‘…’;
}
while (list($key) = each($array)) {
$array[$key] = $array[$key] . ‘…’;
}
总结:通常认为,foreach涉及到值复制,一定会比while慢,但实际上,如果仅仅是在循环里进行数组的读操作,那么foreach是很
快的,这是因为PHP采用的复制机制是“引用计数,写时复制”,也就是说,即便在PHP里复制一个变量,最初的形式从根本上说其实
仍然是引用的形式,只有当变量的内容发生变化时,才会出现真正的复制,之所以这么做是出于节省内存消耗得目的,同时也提升了
复制的效率。这样看来,foreach的高效读操作就不难理解了。另外,既然foreach不适合处理数组写操作,那么我们可以得出一个结
论,多数情况下,类似foreach ($array as $key => $value)形式的做数组写操作得代码都应该被替换成while (list($key) =
each($array))。这些技巧产生的速度差异在小项目里可能并不明显,但是在类似框架这样的大项目中,一次请求动辄便会涉及到几
百几千几万次数组循环操作,差异就会明显放大。
波比源码 » PHP编程中foreach、while的性能比较
order levofloxacin 250mg online cheap buy levofloxacin online cheap
avodart online buy order dutasteride sale zofran 4mg oral
buy acillin order erythromycin 500mg order erythromycin 500mg without prescription
buy sildenafil without prescription careprost over the counter buy methocarbamol pills
sildenafil 50mg generic cheap sildenafil 100mg order estradiol 1mg
lamotrigine without prescription prazosin over the counter retin gel drug
tadalis 20mg without prescription avanafil 200mg ca order voltaren 50mg without prescription
purchase isotretinoin online cheap order azithromycin 250mg online cheap azithromycin order
indocin 50mg drug buy indocin 50mg sale cost amoxicillin 250mg
generic cialis india Cost of viagra sildenafil cost
anastrozole brand where to buy viagra in singapore viagra 100mg without prescription
generic accutane 40mg amoxicillin 1000mg us stromectol 0.5 mg
altace 10mg tablet irbesartan 150mg cost buy azelastine 10ml online cheap
clonidine order purchase tiotropium bromide sale spiriva sale
hytrin 1mg drug terazosin 1mg ca buy sulfasalazine sale
alendronate 70mg uk purchase pepcid generic famotidine 40mg canada
zoloft order buy zoloft 50mg generic viagra 100mg for sale
cialis otc pyridium 200mg generic generic symmetrel 100 mg
order avlosulfon 100 mg without prescription aceon 4mg canada purchase aceon online cheap
order provera 5mg online cheap microzide without prescription periactin 4mg price
generic provigil buy modafinil 100mg online cheap ivermectin 2mg
luvox price order cymbalta online order glucotrol 10mg online
accutane order order prednisone without prescription deltasone 20mg for sale
piracetam 800mg us order piracetam 800 mg generic viagra 50mg cost
buy azithromycin 250mg without prescription prednisolone 40mg oral oral gabapentin 100mg
buy tadalafil 5mg online cheap real cialis order sildenafil 50mg online
brand furosemide 40mg doxycycline cheap order hydroxychloroquine 200mg generic
cialis ca betnovate 20 gm cheap clomipramine 25mg over the counter
buy sporanox 100mg generic generic progesterone 100mg tindamax 300mg price
buy metformin 1000mg online cheap glycomet for sale online order cialis 10mg sale
order norvasc tadalafil order buy tadalafil 5mg online
purchase clozaril generic order clozaril 50mg generic cost dexamethasone 0,0,5 mg
sildenafil 50 mg buy lisinopril 10mg online cheap lisinopril 10mg canada
order prilosec 10mg pills buy cheap essays online online roulette wheel
linezolid 600 mg tablet real money games online casino gambling
help with thesis write essays for me blackjack online free
vardenafil 20mg sale buy vardenafil online cheap medrol australia
order essays online top essay writers buy viagra online
tadalafil medication order generic tadalafil 10mg sildenafil 50mg tablet
aristocort order online buy desloratadine 5mg generic clarinex online order
order dapoxetine 60mg for sale order misoprostol online cheap levothyroxine order online
order tadalafil 20mg pill inderal 20mg pills clopidogrel 75mg usa
cozaar 25mg brand topiramate order order topamax 100mg online
buy baclofen 25mg sale buy baclofen online purchase toradol generic
order imitrex 50mg generic order sumatriptan 50mg generic dutasteride sale
ranitidine for sale online brand ranitidine celebrex canada
online poker real money online casino with free signup bonus real money usa legitimate online slots for money
cialis 40mg cost order generic tadalafil 5mg purchase cipro generic
diflucan cheap cheap sildenafil 50mg purchase sildenafil without prescription
cost cephalexin 250mg erythromycin 500mg usa erythromycin 250mg canada
price of cialis buy sildenafil 100mg pill viagra 200 mg
sildenafil 25 mg buy estrace 2mg generic buy lamictal 50mg pills
deltasone drug prednisone 10mg ca cheap amoxil 250mg
free slot cialis 10mg price cialis coupons
free slot games online online casino roulette provigil 200mg sale
cost tiotropium bromide 9 mcg order minocycline 50mg online terazosin price
generic cialis cost poker online play play slots for real money united states
tadalafil brand name female cialis pill cheap cialis
online slots real money canada online pharmacy help writing paper
order benicar 20mg sale divalproex 500mg usa purchase divalproex online
lanoxin 250 mg pill molnunat generic purchase molnunat sale
buy pamelor online nortriptyline 25mg pills buy paxil generic
order doxycycline 200mg sale order doxycycline 100mg pill medrol 4 mg tablet
buy pepcid prograf 5mg price order mirtazapine generic
order generic ropinirole 2mg trandate 100mg brand generic labetalol 100 mg
buy tadalafil online cheap clopidogrel 150mg without prescription order generic trimox 500mg
buy clomiphene 100mg online order generic prednisolone 5mg prednisolone tablet
buy fildena without prescription buy sildenafil 50mg for sale finasteride pills
order stromectol buy stromectol 12mg pill deltasone 40mg generic
buy absorica online buy amoxicillin without prescription zithromax cost
order generic prednisolone 5mg order prednisolone 10mg buy furosemide generic
doxycycline 100mg sale cheap zovirax order zovirax 400mg for sale
purchase avodart sale avodart uk buy xenical 60mg for sale
ditropan 5mg brand prograf 1mg pill cheap trileptal
order zocor 20mg sale purchase promethazine online sildalis cheap
order generic dapsone 100mg buy dapsone 100 mg without prescription order atenolol without prescription
alfuzosin online diltiazem drug buy diltiazem generic
sildenafil professional viagra 25mg cialis 40mg sale
order levofloxacin 500mg generic zyban 150 mg without prescription zyban 150 mg canada
escitalopram without prescription order prozac sale naltrexone uk
order lipitor 10mg for sale lipitor canada order viagra 50mg
order letrozole 2.5mg sale letrozole price viagra sale
order cialis for sale best ed pills top rated ed pills
ivermectin 3 mg tablets stromectol 3mg usa isotretinoin 40mg tablet
amoxil 1000mg tablet amoxicillin 1000mg canada prednisolone 10mg brand
order prednisolone 40mg online order generic prednisolone 20mg buy lasix pill diuretic
albuterol 2mg price augmentin cost buy synthroid 75mcg pills
cheap clomiphene buy vardenafil online cheap plaquenil 400mg cheap
order doxycycline 100mg online cheap augmentin drug order augmentin 625mg generic
synthroid usa generic clomiphene order levitra 20mg
albenza pills albendazole cost buy medroxyprogesterone 5mg generic
glycomet online glucophage over the counter amlodipine 5mg generic
praziquantel 600 mg for sale buy generic microzide 25mg buy cyproheptadine 4mg online cheap
order xenical 60mg for sale order zyloprim 100mg generic order allopurinol generic
purchase cozaar online order topamax generic how to get topamax without a prescription
sumatriptan 25mg oral imitrex 50mg price dutasteride pills
tetracycline 500mg brand tetracycline 500mg canada order baclofen 10mg sale
ketorolac us colchicine price propranolol canada
generic betamethasone sporanox medication itraconazole 100mg uk
buy progesterone online olanzapine 10mg ca olanzapine 10mg oral
generic starlix 120 mg nateglinide 120 mg over the counter buy candesartan pill
bystolic online buy bystolic 5mg without prescription order generic clozapine 100mg
cialis 10mg usa Buy online viagra sildenafil order online
duricef drug buy proscar 5mg for sale proscar over the counter
order fluconazole 100mg online buy acillin no prescription order cipro 500mg generic
purchase mebendazole pills tadalafil oral buy tadalis pills
avana 100mg canada diclofenac 50mg pill purchase voltaren without prescription
buy nolvadex 10mg pill cost budesonide cefuroxime 500mg ca
minomycin price buy minocin 50mg sale pioglitazone cost
purchase accutane pills buy azithromycin without prescription buy cheap generic azithromycin
otc cialis tadalafil 40mg oral tadalafil generic
furosemide order online doxycycline us cost albuterol
levitra 10mg drug buy plaquenil 400mg online cheap plaquenil ca
order altace without prescription buy ramipril 10mg online arcoxia cheap
order olmesartan 10mg generic benicar 20mg ca divalproex oral
order coreg 6.25mg without prescription carvedilol 6.25mg without prescription buy chloroquine 250mg pills
cheap baricitinib 4mg buy olumiant pills order lipitor 40mg pills
buy montelukast online cheap order symmetrel 100 mg for sale avlosulfon cheap
norvasc online buy amlodipine 10mg without prescription buy omeprazole 10mg online cheap
metoprolol 100mg tablet metoprolol online order methylprednisolone 4mg without a doctor prescription
purchase dapoxetine pills buy misoprostol without prescription oral xenical 60mg
aristocort 10mg oral clarinex brand order claritin 10mg without prescription
order generic diltiazem where to buy acyclovir without a prescription purchase allopurinol pill
bactrim 960mg generic purchase bactrim without prescription buy clindamycin no prescription
erythromycin 250mg oral fildena over the counter order tamoxifen 20mg online
brand clopidogrel 75mg order coumadin coumadin 5mg brand
budesonide generic careprost spray order careprost eye drops
buy reglan 20mg buy metoclopramide for sale esomeprazole 40mg oral
avodart 0.5mg oral mobic pill cost meloxicam
order propecia 5mg generic viagra for men over 50 sildenafil 50mg uk
tadacip cost indomethacin 50mg uk indomethacin usa
lamisil 250mg ca cefixime for sale trimox 500mg drug
oral anastrozole anastrozole online buy generic clonidine 0.1mg
order azulfidine without prescription order sulfasalazine 500mg generic oral calan 120mg
buy meclizine cheap order meclizine generic minocycline 100mg cheap
buy imuran generic digoxin 250mg us how to get telmisartan without a prescription
ed pills that work cheap viagra 100mg sildenafil 50mg brand
molnunat 200 mg tablet naprosyn 250mg sale buy omnicef generic
cheap erectile dysfunction cialis usa cialis for men
buy cheap generic hytrin arava 10mg uk generic cialis cost
fexofenadine pills purchase altace without prescription order amaryl 4mg pill
buy irbesartan 300mg sale buy buspirone tablets buspar online buy
buy praziquantel 600mg pill hydrochlorothiazide 25 mg uk purchase periactin online cheap
buy panadol pills oral anacin 500mg order famotidine generic
clomipramine 50mg pill purchase prometrium order progesterone 200mg generic
order tindamax 300mg online cheap zyprexa buy online bystolic price
buy valsartan 80mg cost clozapine 50mg order combivent for sale
oxcarbazepine 300mg sale order trileptal online actigall 300mg usa
order dexamethasone without prescription linezolid 600mg drug how to buy starlix
bupropion for sale buy atomoxetine cheap buy strattera no prescription
order quetiapine 50mg without prescription order escitalopram 20mg generic escitalopram pills
ciplox oral ciplox 500 mg brand buy cefadroxil 250mg pill
cost sarafem 40mg buy naltrexone pills for sale letrozole 2.5 mg pills
buy lamivudine without prescription buy epivir generic buy accupril 10 mg generic
zebeta tablet terramycin uk buy oxytetracycline 250 mg sale
where to buy frumil without a prescription clindamycin price acyclovir for sale