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
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...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.