如果您的数组始终被一致索引(例如,“ page1”始终位于索引“ 0”),则它很简单:
$List = array('page1', 'page2', 'page3', 'page4', 'page5');$CurrentPage = 3; // 'page4'while (key($List) !== $CurrentPage) next($List); // Advance until there's a match我个人不依赖自动索引,因为总是有可能自动索引会更改。您应该考虑显式定义键:
$List = array( '1' => 'page1', '2' => 'page2', '3' => 'page3',);
编辑: 如果要测试数组的值(而不是键),请使用
current():
while (current($List) !== $CurrentPage) next($List);



