Php 运行递归时出错
如果运行函数,则返回服务器配置错误Php 运行递归时出错,php,Php,如果运行函数,则返回服务器配置错误 function build_path($cid) { $result = array(); $DB = new MySQLTable; $DB->TblName = 'shop_categories'; $where['cat_id']['='] = $DB->CleanQuest($cid); $res = $DB->Select('cat_i
function build_path($cid)
{
$result = array();
$DB = new MySQLTable;
$DB->TblName = 'shop_categories';
$where['cat_id']['='] = $DB->CleanQuest($cid);
$res = $DB->Select('cat_id,cat_name,cat_parent', $where);
if($res !== 'false')
{
$pid = mysql_fetch_array($res);
if($pid['cat_parent'] !== 0)
{
Echo $pid['cat_parent'];
build_path($pid['cat_parent']);
} else {
Echo $pid['cat_id'];
return true;
}
}
return false;
}
我在这里找不到错误。请帮忙
对不起,打扰你们了。问题在于比较'if($pid['cat\u parent']!==0):$pid['cat\u parent']是一个带int(0)的字符串
我可以构建此函数来存储完整路径而不使用全局变量和会话变量吗?要检查的内容:
另外,将
error\u reporting
设置为max,并检查错误日志。我猜可能是堆栈溢出(递归太深)或内存限制问题(占用太多内存并被杀死).错误日志中有什么内容?此外,在类型敏感模式下,将$res与字符串'false'进行核对是毫无意义的。您的意思是如果($res!==false)
?如果没有父项,字段($pid['cat\u parent']
)的内容实际上是0
而不是null
?
function build_path($cid) {
static $done = array();
if (isset($done[$cid])) {
throw new Exception('We have already looked up CID: '.$cid);
} else {
$done[$cid] = true;
}
//.......
}