mc2w Posted March 9, 2009 Share Posted March 9, 2009 I'm currently developing a wordpress plugin, and I want to let users select or deselect certain categories and store their choices in an array. Problem is, I don't want them to have to choose every time they load the options page, I want their previous selections to be preselected. So, lets say I have an array called "cats", how would I check to see if something like "Random" was within the array, and have it spit out a true or false variable (so I can setup some if statements)? My code will probably look something like this: $enabled = get_option('SS_cats'); foreach($cats as $category){ if(magic_function_that_i_need($category) = TRUE){ echo '<input type="checkbox" name="enabledcats" value="'.$category.'" checked="checked" />'; }else{ echo '<<input type="checkbox" name="enabedcats" value="'.$category.'"/> } } Or something like that (if something is wrong in there besides the magic_function thing, lemme know). Link to comment https://forums.phpfreaks.com/topic/148561-check-array-for-string/ Share on other sites More sharing options...
.josh Posted March 9, 2009 Share Posted March 9, 2009 $string = "cats"; $array = array('cats','dogs','mice'); if (in_array($string, $array)) { // true, do something } else { // false, do something } Link to comment https://forums.phpfreaks.com/topic/148561-check-array-for-string/#findComment-780124 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.