$teams = array(1, 2, 3, 4, 5, 6, 7, 8);
$game1 = array(2, 4, 6, 8);
$game2 = array();
if teams[x]
is not in game1
then insert into game2
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 ", ";
}
Im expecting the result to be:
1, 3, 5, 7,
However, im getting:
1, 1, 1, 1, 3, 3, 3, 3, 4, 5, 5, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8,
How can i improve this? Thanks