大网数据广告活动
PHP 语言与运行手册

MultipleIterator::current · Gets the current elements of the attached iterators

· 52CE 我爱测

MultipleIterator::current — Gets the current elements of the attached iterators

MultipleIterator::current

(PHP 5 >= 5.3.0, PHP 7, PHP 8)

MultipleIterator::current — Gets the current elements of the attached iterators

说明

public function MultipleIterator::current(): array

Gets the current elements of all attached iterators, by calling Iterator::current() on each valid one.

With MultipleIterator::MIT_KEYS_NUMERIC, the elements are listed in the order in which the iterators were attached. With MultipleIterator::MIT_KEYS_ASSOC, they are keyed by the information associated with each iterator by MultipleIterator::attachIterator().

参数

此函数没有参数。

返回值

An array containing the current elements of each attached iterator. With MultipleIterator::MIT_NEED_ANY, null is used for the iterators that are not valid.

错误/异常

Throws a RuntimeException if no iterator is attached, or if MultipleIterator::MIT_NEED_ALL is set and at least one attached iterator is not valid.

Throws an InvalidArgumentException if MultipleIterator::MIT_KEYS_ASSOC is set and an iterator was attached without associated information.

更新日志

版本 说明
8.1.0 A RuntimeException is now thrown if MultipleIterator::current() is called when no iterator is attached. Previously, false was returned.

示例

示例 #1 MultipleIterator::current() example

<?php
$iterator = new MultipleIterator(MultipleIterator::MIT_NEED_ANY | MultipleIterator::MIT_KEYS_ASSOC);
$iterator->attachIterator(new ArrayIterator(['a' => 'apple', 'b' => 'banana']), 'fruit');
$iterator->attachIterator(new ArrayIterator(['x' => 'red']), 'color');

$iterator->rewind();
while ($iterator->valid()) {
    var_dump($iterator->current());
    $iterator->next();
}
?>

以上示例会输出:

array(2) {
  ["fruit"]=>
  string(5) "apple"
  ["color"]=>
  string(3) "red"
}
array(2) {
  ["fruit"]=>
  string(6) "banana"
  ["color"]=>
  NULL
}

参见

来源:PHP Documentation Group · 作者与贡献记录 · CC BY 3.0。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
PHP Documentation Group
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。