current

(PHP 3, PHP 4, PHP 5)

current -- 返回陣列中的現用的單元

說明

mixed current ( array &array )

每個陣列中都有一個內定的指標指向它「現用的的」單元,起始指向插入到陣列中的第一個單元。

current() 函數返回現用的被內定指標指向的陣列單元的值,並不搬移指標。若果內定指標指向超出了單元清單的末端,current() 返回 FALSE

警示

若果陣列包括有空的單元(0 或是 "",空字串)則本函數在碰到這個單元時也返回 FALSE。這使得用 current() 不可能判斷是否到了此陣列清單的末端。要正確遍歷可能含有空單元的陣列,用 each() 函數。

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

<?php
$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';
?>

參見 end()key()next()prev()reset()