使用array_intersect在受控for循环中出现未定义的偏移量错误

I am getting an undefined offset error for the 2 lines I have marked near the bottom of this code. From what I can see it is in a controlled for loop, but obviously something is amiss.

I think that array_intersect creates an array of the shared values between $temparray1 and $temparray2.

$temparray1 = (1,2,3,4,5,6);
$temparray2 = (5,5,6,7,8,9);

$array3 = array_intersect($temparray1, $temparray2);

if (!empty($array3)) {
    $match = true;
} else {
    $match = false;
} 

if ($match === true){
    $tempcount = count($array3);
    $i = 0;
    while ($i < $tempcount){
        //UNDEFINED OFFSET ERROR FOR NEXT 2 LINES
        if(!in_array($array3[$i],$scheduled_groups)){
            $insertgroup = $array3[$i];
            $i++;
        } // End of ifarray
    } // End of while
}