Heim  >  Artikel  >  Backend-Entwicklung  >  玩转php递归函数:php递归函数返回值问题终极解决办法

玩转php递归函数:php递归函数返回值问题终极解决办法

WBOY
WBOYOriginal
2016-07-25 08:51:262254Durchsuche
在php递归函数中,经常会遇到递归函数无返回值的问题,那么在php实现的递归中如何正确处理返回值呢,php递归函数无返回值怎么办,可以参考下本文的实例分析。

一、php递归函数的返回值

例1:

复制代码 代码示例:

function test($i){ $i-=4; if($i

test($i); } }

echo test(30)." ";

注意,以上代码中else内里是有问题的,条件$i

例2,修改php递归函数为:

复制代码 代码示例:

function test($i){ $i-=4; if($i

return test($i); } }

echo test(30)." ";

二、php递归函数返回值问题



Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn