How to click Next and increment the i var?

I have a PHP page.
It holds the entire images inside array images[]

My goal is that on each NEXT the HTML page will display the next image.

I use the i var to increment by +1

But once I click NEXT, the page is refreshing and always shows i=0

<? php echo get_permalink( $images[i+1] ); ?>

What’s the get_permalink function supposed to do?
If the page is reloaded, the array would by default begin with index 0 which is the first image.
This is what happens if you request another page to view the next image.

In a simple implementation, you can use sessions to hold the index of the last image that was clicked.
Questions?