What potential issue can arise when trying to display an extra dataset after every third dataset in PHP?

One potential issue that can arise when trying to display an extra dataset after every third dataset in PHP is keeping track of the current iteration count. To solve this issue, you can use a counter variable that increments with each iteration and check if the current iteration is a multiple of 3 to display the extra dataset.

<?php
$datasets = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
$counter = 1;

foreach($datasets as $data) {
    echo $data;

    if($counter % 3 == 0) {
        echo " Extra dataset";
    }

    echo "<br>";
    $counter++;
}
?>