Jump to content

Check array for string?


mc2w

Recommended Posts

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

Archived

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

×
×
  • Create New...

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.