文章的无限分类好像出错了,大家看看是怎么会事?

2016-07-07 15:26 来源:www.chinab4c.com 作者:ecshop专家

点击文章分类后提示:Fatal error: Maximum execution time of 60 seconds exceeded in E:\freehost\ecshop\web\includes\lib_common.php on line 2711


/**
* 过滤和排序所有文章分类,返回一个带有缩进级别的数组
*
* @accessprivate
* @paramint$cat_id上级分类ID
* @paramarray$arr含有所有分类的数组
* @paramint$level级别
* @returnvoid
*/
function article_cat_options($spec_cat_id, $arr)
{
static $cat_options = array();
if (isset($cat_options[$spec_cat_id]))
{
return $cat_options[$spec_cat_id];
}
if (!isset($cat_options[0]))
{
$level = $last_cat_id = 0;
$options = $cat_id_array = $level_array = array();
while (!empty($arr))
{
foreach ($arr AS $key => $value)
{
$cat_id = $value['cat_id'];
if ($level == 0 && $last_cat_id == 0)
{
if ($value['parent_id'] == 0)
{
break;
}
$options[$cat_id] = $value;
$options[$cat_id]['level'] = $level;
$options[$cat_id]['id'] = $cat_id;
$options[$cat_id]['name']= $value['cat_name'];
unset($arr[$key]);
if ($value['has_children'] == 0)
{
continue;
}
$last_cat_id= $cat_id;
$cat_id_array = array($cat_id);
$level_array[$last_cat_id] = ++$level;
continue;
}
if ($value['parent_id'] == $last_cat_id)
{
$options[$cat_id] = $value;
$options[$cat_id]['level'] = $level;
$options[$cat_id]['id'] = $cat_id;
$options[$cat_id]['name']= $value['cat_name'];
unset($arr[$key]);
if ($value['has_children'] > 0)
{
if (end($cat_id_array) != $last_cat_id)
{
$cat_id_array[] = $last_cat_id;
}
$last_cat_id = $cat_id;
$cat_id_array[] = $cat_id;
$level_array[$last_cat_id] = ++$level;
}
}
elseif ($value['parent_id'] > $last_cat_id)
{
break;
}
}
$count = count($cat_id_array);
if ($count > 1)
{
$last_cat_id = array_pop($cat_id_array);
}
elseif ($count == 1)
{
if ($last_cat_id != end($cat_id_array))
{
$last_cat_id = end($cat_id_array);
}
else
{
$level = 0;
$last_cat_id = 0;
$cat_id_array = array();
continue;
}
}
if ($last_cat_id && isset($level_array[$last_cat_id]))
{
$level = $level_array[$last_cat_id];
}
else
{
$level = 0;
}
}
$cat_options[0] = $options;
}
else
{
$options = $cat_options[0];
}
if (!$spec_cat_id)
{
return $options;
}
else
{
if (empty($options[$spec_cat_id]))
{
return array();
}
$spec_cat_id_level = $options[$spec_cat_id]['level'];
foreach ($options AS $key => $value)
{
if ($key != $spec_cat_id)
{
unset($options[$key]);
}
else
{
break;
}
}
$spec_cat_id_array = array();
foreach ($options AS $key => $value)此处为2711行
{
if (($spec_cat_id_level == $value['level'] && $value['cat_id'] != $spec_cat_id) ||
($spec_cat_id_level > $value['level']))
{
break;
}
else
{
$spec_cat_id_array[$key] = $value;
}
}
$cat_options[$spec_cat_id] = $spec_cat_id_array;
return $spec_cat_id_array;
}
}
?>

回答:
程序执行时间改成300秒也不行。大家看看是不是造成死循环了。

没有知道的?查不出原因来??

程序修改,可以到咖啡交流区看下