0

WP_DEBUG is telling me:

Notice: Undefined index: no_cat_base in myplugin.php on line 20

Here's the lines of code where I'm pulling the value of "no_cat_base" from my options array called "myoptions"...

$myoptions = get_option('my_settings');

if($myoptions['no_cat_base']){//This is line 20}

Is the correct fix for this...

if ( isset($myoptions['no_cat_base'])){//do something}
2
  • Not 100% sure, but if you're expecting an array from your setting (i.e. you're pulling action_plugins setting from the database), I believe you have to cast it as an array? Commented Feb 6, 2011 at 4:50
  • Yes, its a multidimensional array. Commented Feb 7, 2011 at 4:02

1 Answer 1

1

just to be on the safe side use:

if (array_key_exists('no_cat_base', $myoptions) && isset($myoptions['no_cat_base'])){
//do your thing
}
2
  • isset is enough, no need for array_key_exists Commented Feb 6, 2011 at 10:38
  • 1
    As i posted "just to be on the safe side", but yes isset is enough Commented Feb 6, 2011 at 10:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.