0

如果$point333(例如),我希望current($ids)444

$ids = array(111, 222, 333, 444);
$point = 333;

如果$point444current($ids)111等等。


我有这段代码,但我正在寻找更简单的东西:

$ids = array(111, 222, 333, 444, 555);
$point = array_search(555, $ids);

while(key($ids) != $point) {
    next($ids);
}

$point = next($ids);

if($point == NULL) {
    $point = reset($ids);
}

echo $point;
4

2 回答 2

2

找不到下一个时重置数组

while(key($ids) != $point) {
    if (next($ids) === false) reset($ids);
}
于 2013-08-08T10:43:37.750 回答
0
while(key($ids) != $point) {
    next($ids);
}

$toEcho = next($ids);
if (!$toEcho) {
    $toEcho = reset($ids);
} 
于 2013-08-08T10:49:39.040 回答