Conditional in foreach loop is outputting content twice

There’s some code missing from your question – the code where your slides are actually output.

The foreach loop you’ve posted only sets the variables, and the actual output happens below the loop.

So, all you’re doing on the fourth slide is avoiding setting the variables… hence the slide is still output, but using the third slide’s variables.

Your if checkbox logic looks ok; you just need to include the logic on the actual code that outputs the slides too.