In this code:
<?php
    $array = array(
        'pop0',
        'pop1',
        'pop2',
        'pop3',
        'pop4',
        'pop5',
        'pop6',
        'pop7',
        'pop8'
    );
    echo "Tot Before: ".count($array)."<br><br>";
    for ($i=0; $i<count($array); $i++) {
        if ($i === 3) {
            unset($array[$i]);
        }
        echo "Count: ".count($array). " - Position: ".$i."<br>";
    }
    echo "<br> Tot After: ".count($array)."<br>";
?>
The result is:
---
Tot Before: 9
Count: 9 - Position: 0
Count: 9 - Position: 1
Count: 9 - Position: 2
Count: 8 - Position: 3
Count: 8 - Position: 4
Count: 8 - Position: 5
Count: 8 - Position: 6
Count: 8 - Position: 7
Tot After: 8
---
The position 8 is skipped, because the "expr2" {{ $i<count($array) }} is evaluated again, for each cycle.
The solution is:
<?php
    
    $array = array(
        'pop0',
        'pop1',
        'pop2',
        'pop3',
        'pop4',
        'pop5',
        'pop6',
        'pop7',
        'pop8'
    );
    echo "Tot Before: ".count($array)."<br><br>";
    $count = count($array);
    for ($i=0; $i<$count; $i++) {
        if ($i === 3) {
            unset($array[$i]);
        }
        echo "Count: ".count($array). " - Position: ".$i."<br>";
    }
    echo "<br> Tot After: ".count($array)."<br>";
    
?>