略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: NoRewindIterator::__construct

2024-11-14

NoRewindIterator::__construct

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

NoRewindIterator::__constructConstruct a NoRewindIterator

说明

public NoRewindIterator::__construct(Iterator $iterator)

Constructs a NoRewindIterator.

参数

iterator

The iterator being used.

范例

示例 #1 NoRewindIterator::__construct() example

The second loop does not output because the iterator is only used once, as it does not rewind.

<?php
$fruit 
= array('apple''banana''cranberry');

$arr = new ArrayObject($fruit);
$it  = new NoRewindIterator($arr->getIterator());

echo 
"Fruit A:\n";
foreach( 
$it as $item ) {
    echo 
$item "\n";
}

echo 
"Fruit B:\n";
foreach( 
$it as $item ) {
    echo 
$item "\n";
}
?>

以上例程的输出类似于:

Fruit A:
apple
banana
cranberry
Fruit B:

参见

add a noteadd a note

User Contributed Notes

There are no user contributed notes for this page.

官方地址:https://www.php.net/manual/en/norewinditerator.construct.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3