next

(PHP 3, PHP 4, PHP 5)

next --  將陣列中的內定指標向前搬移一位

說明

mixed next ( array &array )

返回陣列內定指標指向的下一個單元的值,或當沒有更多單元時返回 FALSE

next()current() 的行為類似,只有一點區別,在返回值之前將內定指標向前搬移一位。這意味著它返回的是下一個陣列單元的值並將陣列指標向前搬移了一位。若果搬移指標的結果是超出了陣列單元的末端,則 next() 返回 FALSE

警示

若果陣列包括空的單元,或是單元的值是 0 則本函數碰到這些單元也返回 FALSE。要正確遍歷可能含有空單元或是單元值為 0 的陣列,參見 each() 函數。

例子 1. next() 及關聯函數的用法示例

<?php
$transport 
= array('foot''bike''car''plane');
$mode current($transport); // $mode = 'foot';
$mode next($transport);    // $mode = 'bike';
$mode next($transport);    // $mode = 'car';
$mode prev($transport);    // $mode = 'bike';
$mode end($transport);     // $mode = 'plane';
?>

參見 current()end()prev()reset()