代码

$CATEGORY = array(
		'1'=>array('catid'=>'1','catname'=>'新闻中心','arrparentid'=>'0'),
		'2'=>array('catid'=>'2','catname'=>'世界新闻','arrparentid'=>'0,1'),
		'3'=>array('catid'=>'3','catname'=>'国内新闻','arrparentid'=>'0,1'),
);
function catpos($catid, $urlrule = '')
{
	global $CATEGORY;


	if(!isset($CATEGORY[$catid])) return '';
	$pos = '';
	$arrparentid = array_filter(explode(',', $CATEGORY[$catid]['arrparentid'].','.$catid));
	foreach($arrparentid as $catid)
	{
		if($urlrule) eval("\$url = \"$urlrule\";");
		else $url = $CATEGORY[$catid]['url'];
		$pos .= '<a href="'.$url.'">'.$CATEGORY[$catid]['catname'].'</a>';
	}
	return $pos;
}
echo catpos(3);
登录后复制
09-14 01:10