current函数返回数组中的当前单元的值
基本语法
mixed current ( array &$array )
参数介绍
| 参数 | 描述 |
|---|---|
| array | 必需。规定要使用的数组。 |
current() 函数返回数组中的当前元素(单元)。每个数组中都有一个内部的指针指向它“当前的”元素,初始指向插入到数组中的第一个元素。
返回值
current() 函数返回当前被内部指针指向的数组单元的值,并不移动指针。如果内部指针指向超出了单元列表的末端, current() 返回 FALSE 。
注意:
如果数组包含 boolean FALSE 的单元则本函数在碰到这个单元时也返回 FALSE ,使得不可能判断是否到了此数组列表的末端。 要正确遍历可能含有空单元的数组,用 each() 函数。
实例:
<?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) { }
?>
继续阅读与本文标签相同的文章
-
中国第4大运营商来袭,携号转网套路多,移不动联不通信不过拜拜
2026-05-14栏目: 教程
-
美国让华为更强大,9个月入账6千亿增速超2成,5G合同已签60多份
2026-05-14栏目: 教程
-
未来几年,这4个大学专业最吃香,前景广阔堪称铁饭碗!
2026-05-14栏目: 教程
-
这间屋子没有电话
2026-05-14栏目: 教程
-
曾经扬言“我要摧毁人类”的机器人,在拥有公民身份后,近况如何?
2026-05-14栏目: 教程
