Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.