gibigbig Posted May 28, 2010 Share Posted May 28, 2010 I have an array of image id's: $all_images = array("33","44","46","100","120","600","907","1200","1239","1299","1305"); as an example and i have the current id of the page from the $_GET['imageid'], as so: $imageid = $_GET['imageid']; what i would like to do is to somehow find a way to see choose the imageid in $all_images directly AFTER the $imageid value. for example, if the $imageid = 600; then i would like to find a way to get the id right after this, "907" (a "next" button) any idea how i can do this? Quote Link to comment Share on other sites More sharing options...
jdavidbakr Posted May 28, 2010 Share Posted May 28, 2010 Try this: reset($counter); $nextimage = null; do { if (current($counter) == $_GET['imageid']) { if (next($counter)) { $nextimage = current($counter); } else { // At the end of the array } break; } } while (next($counter)); if ($nextimage) { // We found the next image } else { // Either the image we received isn't in the array or we're at the end of the array } Quote Link to comment Share on other sites More sharing options...
Cagecrawler Posted May 28, 2010 Share Posted May 28, 2010 This should work: $all_images[array_search($imageid, $all_images)+1] Quote Link to comment Share on other sites More sharing options...
jdavidbakr Posted May 28, 2010 Share Posted May 28, 2010 This should work: $all_images[array_search($imageid, $all_images)+1] A-ha, I knew there had to be that function, just couldn't find it Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted May 28, 2010 Share Posted May 28, 2010 What happens when $imageid is the last element in the array? You better check for boundary conditions... Ken Quote Link to comment Share on other sites More sharing options...
gibigbig Posted May 28, 2010 Author Share Posted May 28, 2010 Thank you so much jdavidbakr + rep confirmed working Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.