reset (PHP 3, PHP 4, PHP 5)
reset -- 將數組的內部指標指向第一個單元
說明
mixed reset ( array &array )
reset() 將 array 的內部指標倒回到第一個單元並返回第一個數組單元的值,如果數組為空白則返回 FALSE。
例 1. reset() 例子
複製代碼 代碼如下:
$array = array('stepone', 'step two', 'step three', 'step four');
//by default, the pointer is on the first element
echo current($array) . "
\n"; // "stepone"
// skip twosteps
next($array);
next($array);
echo current($array) . "
\n"; // "stepthree"
//reset pointer, start again on step one
reset($array);
echo current($array) . "
\n"; // "stepone"
?>
next(PHP 3, PHP 4, PHP 5)
next -- 將數組中的內部指標向前移動一位
說明
mixed next ( array &array )
返回數組內部指標指向的下一個單元的值,或當沒有更多單元時返回 FALSE。
next() 和 current()的行為類似,只有一點區別,在傳回值之前將內部指標向前移動一位。這意味著它返回的是下一個數組單元的值並將數組指標向前移動了一位。如果移動指標的結果是超出了數組單元的末端,則next() 返回 FALSE。
警告
如果數組包含空的單元,或者單元的值是 0 則本函數碰到這些單元也返回 FALSE。要正確遍曆可能含有空單元或者單元值為 0的數組,參見 each() 函數。
例 1. next() 及相關函數的用法樣本
複製代碼 代碼如下:
$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(PHP 3, PHP 4, PHP 5)
current -- 返回數組中的當前單元
說明
mixed current ( array &array )
每個數組中都有一個內部的指標指向它“當前的”單元,初始指向插入到數組中的第一個單元。
current() 函數返回當前被內部指標指向的數組單元的值,並不移動指標。如果內部指標指向超出了單元列表的末端,current()返回 FALSE。
警告
如果數組包含有空的單元(0 或者 "",Null 字元串)則本函數在碰到這個單元時也返回 FALSE。這使得用 current()不可能判斷是否到了此數組列表的末端。要正確遍曆可能含有空單元的數組,用 each() 函數。
例 1. current() 及相關函數的用法樣本
複製代碼 代碼如下:
$transport = array('foot', 'bike', 'car', 'plane');
$mode = current($transport); //$mode = 'foot';
$mode = next($transport); // $mode ='bike';
$mode = current($transport); //$mode = 'bike';
$mode = prev($transport); // $mode ='foot';
$mode = end($transport); // $mode ='plane';
$mode = current($transport); //$mode = 'plane';
?>
http://www.bkjia.com/PHPjc/328073.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/328073.htmlTechArticlereset (PHP 3, PHP 4, PHP 5) reset -- 將數組的內部指標指向第一個單元 說明 mixed reset ( array lt;?php $array = array('stepone', 'step two', 'step three', 'step four...