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无尽的。

热门文章

热工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

适用于 Eclipse 的 SAP NetWeaver 服务器适配器
将Eclipse与SAP NetWeaver应用服务器集成。

MinGW - 适用于 Windows 的极简 GNU
这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

Dreamweaver CS6
视觉化网页开发工具

WebStorm Mac版
好用的JavaScript开发工具