使用字符串设置当前数组


Set current array using a string

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

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

如果$point444当前($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;

未找到下一个时重置阵列

while(key($ids) != $point) {
    if (next($ids) === false) reset($ids);
}
while(key($ids) != $point) {
    next($ids);
}
$toEcho = next($ids);
if (!$toEcho) {
    $toEcho = reset($ids);
}