If you mix yielding values with keys and yielding values without keys, the result is the same as adding values to an array with or without keys.
<?php
function gen() {
yield 'a';
yield 4 => 'b';
yield 'c';
}
$t = iterator_to_array(gen());
var_dump($t);
?>
The result is an array [0 => 'a', 4 => 'b', 5 => 'c'], just as if you had written
<?php
$t = [];
$t[] = 'a';
$t[4] = 'b';
$t[] = 'c';
var_dump($t);
?>
With the key given to 'c' being incremented from the previous numeric index.