我在使用带有变量的functions.php文件时遇到问题
$prev_dept = 0;
$comment_count = 0;
$comment_index = 0;
function setCommentCount($size){
$comment_count = $size;
}
function flowhub_comment($comment, $args, $depth) {
$comment_index ++;
if($depth > 1) {
$line = true;
}
echo '$prev_dept:' . $prev_dept.'<br>';
}我不能访问$comment_index,所以我不能在函数中设置或获取它。我应该怎么做才能解决这个问题?
你的如实
发布于 2010-04-10 01:02:36
$comment_index不在函数范围内,您需要使用global。More details on scoping in PHP。
发布于 2010-04-10 01:03:45
functions.php的工作方式不仅仅是简单的包含,尝试全局它可能会有所帮助。
function setCommentCount($size){
global $comment_count;
$comment_count = $size;
}https://stackoverflow.com/questions/2609367
复制相似问题