Help with For Loop. Values repeating

ChangMleczynski

New Member
\[code\]$teams = array(1, 2, 3, 4, 5, 6, 7, 8);$game1 = array(2, 4, 6, 8);$game2 = array();\[/code\]if \[code\]teams[x]\[/code\] is not in \[code\]game1\[/code\] then insert into \[code\]game2\[/code\]\[code\]for($i = 0; $i < count($teams); $i++){ for($j = 0; $j < count($game1); $j++){ if($teams[$i] == $game1[$j]){ break; } else { array_push($game2, $teams[$i]); } }}for ($i = 0; $i < count($game2); $i++) { echo $game2[$i]; echo ", ";}\[/code\]Im expecting the result to be:\[code\]1, 3, 5, 7,\[/code\]However, im getting:\[code\]1, 1, 1, 1, 3, 3, 3, 3, 4, 5, 5, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8,\[/code\]How can i improve this? Thanks
 
Back
Top