views:

77

answers:

3
$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';
}

gives:

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

What's wrong?

+9  A: 

You've got the arguments mixed up - see in_array():

if (in_array($_GET['module'], $modules)) {
    include $_GET['module'].'.php';
}
Greg
yet another case of people getting bitten by php being inconsistent with needle/haystack ordering.
Kent Fredric
@kent: yet another case of people not using excellent php docs?
SilentGhost
@SilentGhost While I agree the PHP docs are phenomenal, consistent needle/haystack ordering would help those of us who have the functions committed to memory keep the arg order straight.
ceejayoz
PHP can't retroactively fix the ordering.. so get used to it. Use an IDE that tells you what the param order is and you'll never run into this problem again.
Mike B
+1  A: 

wrong order of variable passed to in_array

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

From PHP.NET:

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

Make sure you're needle is: $modules and where you're looking for it is: $_GET['module']. I feel like you mixed those two up. It really should be written like this:

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

Hope that helps!