Home > Backend Development > PHP Tutorial > PHP递归函数的一些疑义

PHP递归函数的一些疑义

WBOY
Release: 2016-06-13 12:19:33
Original
936 people have browsed it

PHP递归函数的一些疑问
不多说了,直接在代码中注释我的问题

<?php<br />function digui($i = 0) {<br />	if ($i < 3) {<br />		digui(++ $i);<br />		echo $i;//当满足$i < 3已经进行递归了,当不满足,也就跳过这个判断了。为什么这里会被执行!<br />	}<br />	return $i;//为什么返回的不是最后一次递归后的值,3<br />}<br />$r = digui();<br />var_dump($r);
Copy after login

------解决思路----------------------
digui(++ $i);
改为
$i = digui(++ $i);

digui 函数有返回值,你总得有个人接住他吧

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template