Jump to content

Archived

This topic is now archived and is closed to further replies.

alexruimy

In_array Function...wrong Datatype?

Recommended Posts

I'm sure there's something wrong here on a basic level that I'm just unaware of. Here're a few lines of code that aren't functioning properly.

The error I'm getting is
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Warning: in_array(): Wrong datatype for second argument in...[/quote]

The relevant code is:

[code]$check = array(
       "service" => "Service",
       "centrifuge" => "Centrifuge",
       "support" => "Support",
       "disinfection" => "Disinfection",
       "main" => "Main",
       "northcontrol" => "North Control");

function echotitle($b){
   if (in_array($b, $check)) {
      echo " - ". ($check[$b]) . " Building";
      } else {
      echo "Overview";}
}[/code]

I'm aware this may not be the most efficient way to make what I'm trying to make happen, but I'm stuck on this now, and really want to make it work. I just learned the "=>" thing in arrays, and I'm trying to put it to use. My guess is that that's where the problem lies.

Any thoughts?

Share this post


Link to post
Share on other sites
Gaah, I can't figure this damn thing out.

I found this at php.net, but can't figure out how to apply it:

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Sometimes, you might want to search values in array, that does not exist. In this case php will display nasty warning:
Wrong datatype for second argument in call to in_array() .

In this case, add a simple statement before the in_array function:

if (sizeof($arr_to_searchin) == 0 || !in_array($value, $arr_to_searchin)) { ... }

In this case, the 1st statement will return true, omitting the 2nd one[/quote]

Share this post


Link to post
Share on other sites
[code]function echotitle($b){
  
   global $check;

   if (sizeof($arr_to_searchin) == 0 || !in_array($value, $arr_to_searchin)) {
      if (in_array($b, $check)) {
         echo " - ". ($check[$b]) . " Building";
         } else {
         echo "Overview";}
   }
}[/code]

I've also added global $check because it was not in the scope.
[a href=\"http://www.php.net/static\" target=\"_blank\"]http://www.php.net/static[/a]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.