foreach ($infs as &$inf) {
   …
}

foreach($infs as $i => $inf) {
   …
}

What’s wrong with the above code? Why after the second loop are there duplicate entries in my $infs array when I did no such thing?

The reason is because I reused the reference variable $inf. That’s a big no-no. To be safe, always unset reference variables when you’re done with them, like this:

foreach ($infs as &$inf) {

}
unset($inf);