PHP code example of pcrov / iteratorstackiterator

1. Go to this page and download the library: Download pcrov/iteratorstackiterator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

pcrov / iteratorstackiterator example snippets


$stack = new \pcrov\IteratorStackIterator();
$stack->push(
    new ArrayIterator([1, 2, 3]),
    new ArrayIterator([4, 5, 6]),
    new ArrayIterator([7, 8, 9])
);

foreach ($stack as $value) {
    echo $value;
}

// output: 789456123

$stack = new \pcrov\IteratorStackIterator();
$stack->push(
    new ArrayIterator([1, 2, 3]),
    new ArrayIterator([4, 5, 6])
);
$stack->rewind();

while ($stack->valid()) {
    $value = $stack->current();
    echo $value;
    $stack->next();

    if ($value === 2) {
        $stack->push(new ArrayIterator([7, 8, 9]));
    }
}

// output: 456127893