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.

This is a WordPress function. If you are working inside of WordPress the answer is a little bit tricker. WordPress does not support sessions, so that’s out.

if your images are named predictable, then pick apart the filename, increment the number, and build the new filename.

If not, then get the file name that was jsut displayed, scan your array to find it, go to the next element in the array (if there is one) and use that filename.

Cheers! :slight_smile: