phparrayse-notices

php array's making the Undefined index: 0 notice go away


Right so i have E_NOTICES on and my code works its just i keep getting "Severity: Notice Message: Undefined index: 0" everytime i try to insert my data into the array with the set key. Its really annoying when ur trying to debug.

What am i doing wrong that will make the notices go away without turning off E_NOTICES?

foreach ($bracketmatches->result() as $row)
{
  if(!isset($bracketdata[$row->position])) 
  {
    $bracketdata[$row->position] = array(); 
  }
  $bracketdata[$row->position] = array("home_name" => $teams[$row->home_id]['team_name']);
}

Solution

  • Is $teams[$row->home_id] definitely defined?

    edit: Quick and dirty test for you:

    foreach ($bracketmatches->result() as $row)
    {
      if(!isset($teams[$row->home_id]))
      {
        die('GOTCHA!!!');
      }
      $bracketdata[$row->position] = array("home_name" => $teams[$row->home_id]['team_name']);
    }