Php功能包括

时间:2014-03-21 20:23:45

标签: php mysql

所以,我正在开发一个动态论坛签名脚本,我已经让它工作了。现在我要做到这一点,只有特定的用户组才能进行特定的设计。 这是我的功能。

function userGroup($rank)
{
    if ($rank == 38)
    { 
    return true;
    }
    else
    {
    return false;
    }       
}

并像这样使用它。

if ($userGroup == true) 
{
...     
}
         else echo('User with that ID doesn\'t exist in the database'); 
}
 else echo('This user hasn\'t in the specific user group'); 

但它不会那样工作。 问候, 拉扎!

3 个答案:

答案 0 :(得分:0)

您创建了一个函数function userGroup($rank),并且您尝试将其称为变量$userGroup。参数怎么了?你的if语句应该是这样的:

if (userGroup($var) == true) { ... }

您实际上并不需要== true

if (userGroup($var)) { ... }

答案 1 :(得分:0)

你不能使用这样的功能。你应该有一个带有效参数的函数调用,如下所示:

if (userGroup($intUserRank)) 
{
...     
}
else echo('User with that ID doesn\'t exist in the database'); 

假设$intUserRank包含用户排名。

答案 2 :(得分:0)

你的功能可能就是这样:

function userGroup($rank)
{
    return ($rank == 38);
}

然后你会像这样使用它:

if (userGroup($some_rank)) 
{
...     
}