alexruimy Posted June 28, 2006 Share Posted June 28, 2006 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? Link to comment https://forums.phpfreaks.com/topic/13098-in_array-functionwrong-datatype/ Share on other sites More sharing options...
alexruimy Posted June 28, 2006 Author Share Posted June 28, 2006 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] Link to comment https://forums.phpfreaks.com/topic/13098-in_array-functionwrong-datatype/#findComment-50397 Share on other sites More sharing options...
poirot Posted June 28, 2006 Share Posted June 28, 2006 [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] Link to comment https://forums.phpfreaks.com/topic/13098-in_array-functionwrong-datatype/#findComment-50403 Share on other sites More sharing options...
alexruimy Posted June 28, 2006 Author Share Posted June 28, 2006 Brilliant! Thanks much. Link to comment https://forums.phpfreaks.com/topic/13098-in_array-functionwrong-datatype/#findComment-50406 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.