Question

I'm receiving the following error in php: Notice: Undefined index: panel_num.

I think I need to use isset() but I can't seem to get it to work with while

global $d;
$i = 1;
while($i <= $d['panel_num']){
$options[] = array(
                      "name" => "Panel".$i,
                        "id" => "panel_".$i,
                       "std" => "",
                      "type" => "panel");
$i++;
}

What is the proper way to resolve this issue?

Was it helpful?

Solution

I think you just need to check for isset() and not empty $d['panel_num']

global $d;
if(isset($d['panel_num']) && !empty($d['panel_num']))
{
    $i = 1;
    while($i <= $d['panel_num']){
    $options[] = array(
                  "name" => "Panel".$i,
                    "id" => "panel_".$i,
                   "std" => "",
                  "type" => "panel");
    $i++;
    }
}

So you will avoid to call your variable if it is not set or it's empty

OTHER TIPS

Check to see if that variable is set before using it:

global $d;
if (isset($d['panel_num']))
{
  $i = 1;
  while($i <= $d['panel_num']){
  $options[] = array(
                      "name" => "Panel".$i,
                        "id" => "panel_".$i,
                       "std" => "",
                      "type" => "panel");
  $i++;
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top