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?
    – Zack
    Feb 6, 2011 at 4:50
  • Yes, its a multidimensional array.
    – Scott B
    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 Feb 6, 2011 at 10:38
  • 1
    As i posted "just to be on the safe side", but yes isset is enough
    – Bainternet
    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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.