Jump to content

Array issue


gibigbig

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/203234-array-issue/
Share on other sites

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
}  

Link to comment
https://forums.phpfreaks.com/topic/203234-array-issue/#findComment-1064823
Share on other sites

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.