iteration in foreach
    foreach($tests as $i => $test){
    
      if ($test->getNumber() == 2) {
          echo $i . $getName() ;
      } else {
         $i--;
      }
    
    }

for example:
number | name
    1  | aaa
    2  | bbb
    1  | ccc
    2  | vvv
    2  | ccc

show me:
   $i $name
    2 bbb
    4 vvv
    5 ccc

instead of:
   $i $name
    1 bbb
    2 vvv
    3 ccc


how can i fix it? 
iteration in foreach
===

    foreach($tests as $i => $test){
    
      if ($test->getNumber() == 2) {
          echo $i . $getName() ;
      } else {
         $i--;
      }
    
    }

for example:
number | name
    1  | aaa
    2  | bbb
    1  | ccc
    2  | vvv
    2  | ccc

show me:
   $i $name
    2 bbb
    4 vvv
    5 ccc

instead of:
   $i $name
    1 bbb
    2 vvv
    3 ccc


how can i fix it? 