php递归问题
- PHP code
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> function test($a) { echo ' '.$a.' '; if($a >0) { test($a-1); }else { echo ''; } echo '<b>'.$a.'</b>'; } test(3)
3 2 1 0 0 1 2 3
各位大侠给解释下运行步骤,或者点参考资料让我去研究下,本人菜鸟。多多包涵
------解决方案--------------------
兄弟,一言难尽了,调用一函数,就得开辟一新栈,递归调用test($a-1)完时,已经输出了3 2 1 0 这个明白不?
然后接着当然是这玩意了,是吧, 明白吗?
最后回收开辟的栈,都要执行这玩意echo ''.$a.''; ~~~
哪里看不明白,指出,尽我所能给你仔细讲解哈~~
------解决方案--------------------
每一层都一样:
1,打印$a
2,进入下一层递归 or 打印
3, 打印$a
那么就是:
打印3, 打印2, 打印1, 打印0, 打印,打印0, 打印1, 打印2, 打印3。
红色是步骤1,蓝色是步骤2.
------解决方案--------------------
test(3) 执行function test :
1. echo $a = 3 然后进入if判断 3>0 执行 test(2) ;这里函数test(3) 还没有执行完的。是先去执行了 test(2) ------- *1;
2. test(2) echo $a = 2 然后判断2>0 执行 test(1) ; 这里也是test(2) 还没有执行完。先去执行了 test(1) ------------*2;
3.test(1) echo $a = 1; 然后判断1>0 执行 test(0) ;这里test(1) 还没有执行完。先去执行了test(0) -----------*3;
4. test(0) echo $a = 0 ;然后判断 0>0 执行了echo echo 0;
5. 4执行完后回到了 *3 ,判断完了后执行 echo $a = 1;
6. 5执行完 回到 * 2 echo $a = 2;
7. 6执行完 回到 *1 echo $a = 3;
这是 一层一层的深入 然后又是一层一层的往外走。

LeicareleasedtheLeicaLuxcameraappfortheAppleiPhoneafewdaysago.However,theappwasnotdevelopedbyLeica,butbyFjorden.ThecompanyhasbeenknownprimarilyforitscameragripsfortheiPhoneandwasacquiredbyLeicainDecember2023.Fo

SincethedemiseofLogitech'spopularHarmonyremotecontrols,themarketforhigh-qualityuniversalremotecontrolshasbeenfragmentedatbest.UnfoldedCircleaimstoavoidthefateoftheHarmonyUltimatebyeliminatinganyserverobligationsorsubs

Anintriguingthird-partycasefortheGalaxyS24Ultra(curr.$1,099.99onAmazon)hasappearedonmarketplaceslikeAliExpress.Astheimagesthroughoutthisarticleshow,thecasehasasimplesiliconeconstruction.However,italsocontainsanEInkd

In2012,theeminentautomotivejournalistJeremyClarksonstatedthattheLamborghiniAventador,whichhewasreviewingatthetime,wouldbeamongthelastcarstofeatureanaturallyaspiratedV12.Morethanadecadelater,V12-poweredsupercarsareal

WhiletheLightPhone2from2018wasstillequippedwithaneconomicale-inkdisplay,theLightPhone3usesanOLEDdisplaythatcanonlydisplaygrayscale.Thereasonfortheswitchtothe3.92-inchOLEDpanelwithitsresolutionof1,240x1,080isth

Audio-TechnicahasunveiledtheATH-S300BTwirelessheadphoneswithhear-throughnoise-cancellation,multipointpairing,and90hoursofbatterylife.Thenoise-cancellingfeaturehasthreemodes:off,on,andhear-through,whereambientsoundscanbehea

Backin2022,whenPCIe7.0wasstartingtotakeshapeasafuturestandard,PCIe5.0wasjusthittingtheservermarketsandtheprospectofseeingPCIe6.0devicesavailableanytimesoon,letalonePCIe7.0ones,wasquitefar-fetched.CurrentlyPCIe5

TheJabraEliteserieshascometoanend,withGNCEOPeterKarlstromerannouncingthediscontinuationofthewirelessearbudswithinthelineupinapressrelease.Petersaysthatthechangingmarketdynamicsandhowchallengingithasbecometogetas


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

VSCode Windows 64位元 下載
微軟推出的免費、功能強大的一款IDE編輯器

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

記事本++7.3.1
好用且免費的程式碼編輯器

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。