Home >Backend Development >PHP Tutorial > PHP递归查询父类,可以echo输出,无法return

PHP递归查询父类,可以echo输出,无法return

WBOY
WBOYOriginal
2016-06-13 12:54:361180browse

求助 PHP递归查询父类,可以echo输出,无法return

<?php<br />
include_once("../conn.php");<br />
function SontoFather($i) <br />
{	<br />
 	$sql = "SELECT `parent_id`,`cate_name` FROM `dlbz_gcategory` WHERE `cate_id`=".$i; <br />
	echo $sql;<br />
	echo '<br/>';<br />
	$result = mysql_query($sql);<br />
	$row=mysql_fetch_row($result);<br />
	//echo $row[1];<br />
	if($row[0]!=0)<br />
	{<br />
		$i = $row[0];<br />
		//echo $i;<br />
		//echo $row[1];<br />
		SontoFather($i);<br />
		<br />
	}<br />
	else<br />
	{  	<br />
		echo $row[1];<br />
		//$j=$row[1];<br />
		return $row[1];<br />
	}<br />
}<br />
echo SontoFather(3);<br />
echo SontoFather(450);<br />
?>

echo SontoFather(3);  这句可以正常输出,即父类自己递归没有问题,可以return返回值,也可echo输出;

echo SontoFather(450); 这句无法正常return输出,但是可以echo输出


php ?return??递归?echo
------解决方案--------------------
16 行
        SontoFather($i);
改为
        return SontoFather($i);
Statement:
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