How add a self growth number in foreach?

Similar to a question I asked months ago. The answer lies in this thread.

Something like this should do it:

<?php 
$images = $page->images()->sortBy('sort', 'asc')
foreach($images as $image): 
  $index = $images->indexOf($images); // add offset if required
?>
  <li><a href="#" uk-slideshow-item="<?= $index ?>"><img src="<?= $image->url() ?>" alt=""></a></li>
<?php endforeach ?>