Index return guid when looping on blocks

foreach ($page->productbuilder()->toBlocks() as $i=>$block) : 

var_dump($i); //"d5d18425-63a8-431a-bb05-3f61397daa93"


I am doing migration from builder to blocks. previously $i was returning (0,1,2…) element index in array. but after migration i am getting guid. Please suggest solution for it. I want array element index in $i

Two options:

A for loop instead of the foreach loop or

$blocks = $page->productbuilder()->toBlocks();
foreach ($blocks as $block) : 
  echo $blocks->indexOf($block);