(PHP 4, PHP 5, PHP 7, PHP 8)
current — 返回數組中的當前值
每個(gè)數組中都有一個(gè)內部的指針指向它“當前的”單元,初始化時(shí)會(huì )指向該數組中的第一個(gè)值。
array
要操作的數組。
current()
函數返回當前被內部指針指向的數組單元的值,并不移動(dòng)指針。如果內部指針指向超出了單元列表的末端,current()
將返回 false
。
版本 | 說(shuō)明 |
---|---|
8.1.0 | 棄用在 object 上調用此函數。 在 object 優(yōu)先使用 get_mangled_object_vars() 或者使用 ArrayIterator。 |
示例 #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';
$arr = array();
var_dump(current($arr)); // bool(false)
$arr = array(array());
var_dump(current($arr)); // array(0) { }
?>