Hi the below loop is supposed to keep looping through each ids. I'm stuck when it comes to the last value it $next = 1 - smallest value..

The value should be the smallest value.

any help is excellent

PHP Code:
foreach ($ids as $key => $id) {
    if (
$id == $photoId) {
        
$next = ($key > (count($ids) - 1) ? $ids[0] : $ids[$key 1]);
        break;
    }