关于递归的应用,请各位指点一下
递归的函数(根据一个分类id,取得这个分类id下面所有的终极id):
function get_child_idarr($id)
{
global $db_prefix,$sql;
static $str=array();
$a=array();
$rs=$sql->query("SELECT id,rou_id FROM ".$db_prefix."prot_class WHERE `p_id`='$id'");
if($sql->num_rows($rs) > 0)
{
while($r=$sql->fetch_assoc($rs))
{
$p_id_num=explode(":",$r['rou_id']);
if(count($p_id_num)==3 AND 1 > $sql->num_rows($sql->query("SELECT id FROM ".$db_prefix."prot_class WHERE `p_id`=$r[id]")))
{
if(array_search($r['id'],$str)===null)
{
$str[]=$r['id'];
}
}
get_child_idarr($r['id']);
}
}else
{
$str[]=$id;
}
$a=$str;
unset($str);
return $a;
}
在任何一个单独的页面运行这个函数,没有问题,但是如果一个页面同时运行2,3...次,
以后每次的结果都会把前一次的结果带进来
第一次:65,66,67
第二次:65,66,67,54 (而如果单独在一个页面运行,只会有54出现,也是我要的结果)
问题就是怎么才能去掉第一次的结果?