Jump to content

how to navigate inside of an array


polemios

Recommended Posts

Hi all,

 

I would like to know how to move the pointer to a specific value in an array. I know how to use prev() and next() to navigate once I set the pointer, but don't know how to set the pointer.

 

Basically, I'm using readdir() to make an array out of a folder of images. That populates an index page with thumbnails. Each thumbnail is linked to a viewing page (view.php) that uses a get variable (the image's filename) to pull in the main image. Once I'm in the view page, I want to be able to use the get variable (the image filename) to search through the readdir() array, using in_array(), and set the pointer position. From that point I could use the prev() and next() function to populate variables for my "prev" and "next" links in my viewer.

 

I know this is trying to reinvent the wheel (i.e. gallery page), but I don't know how else to do it, without using session variables, which I'd prefer not to do.

 

-Thanks.

Link to comment
https://forums.phpfreaks.com/topic/93381-how-to-navigate-inside-of-an-array/
Share on other sites

It just returns the pointers value. I read over the array functions and didn't see anything to be able to set the internal counter of an array to a specific value. I just saw reset, end, next, prev and so on. But you could do something like $key = array_search('value', $array) and then do echo $array[$key], but that may not be what you're looking for since you're using the internal pointers...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.