数组问题

时间:2009-07-17 15:01:30

标签: php arrays

$modules                = array(
'home'                  => 'home',
'login'                 => 'login',
'forum'                 => 'forum',
'topic'                 => 'topic',
'post'                  => 'post',
'profile'               => 'profile',
'moderate'              => 'moderate',
'search'                => 'search',
'ucp'                   => 'usercp',
'ucc'                   => 'usercp',
'pm'                    => 'pm',
'members'               => 'members',
'boardrules'            => 'boardrules',
'groups'                => 'groupcp',
'help'                  => 'help',
'misc'                  => 'misc',
'tags'                  => 'tags',
'attach'                => 'attach'
);

if (in_array($modules, $_GET['module'])) {
include $_GET['module'].'.php';
}

给出:

Warning: in_array() [function.in-array]: Wrong datatype for second argument in d:\public_html\forte.php on line 24

怎么了?

3 个答案:

答案 0 :(得分:10)

你已经把论点搞混了 - 见in_array()

if (in_array($_GET['module'], $modules)) {
    include $_GET['module'].'.php';
}

答案 1 :(得分:1)

错误的变量顺序传递给in_array

 bool in_array  ( mixed $needle  , array $haystack  [, bool $strict  ] )

答案 2 :(得分:0)

来自PHP.NET:

bool in_array ( mixed $needle , array $haystack [, bool $strict ] )

确保你的针是$modules,而你正在寻找的是:$_GET['module']。我觉得你把这两个混在了一起。它真的应该这样写:

in_array($_GET['module'], $modules);

希望有所帮助!