PHP code example of wrossmann / merging-iterator

1. Go to this page and download the library: Download wrossmann/merging-iterator 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/ */

    

wrossmann / merging-iterator example snippets



rossmann\MergingIterator\MergingIterator;

function generate($input) {
    foreach( $input as $item ) {
        yield $item;
    }
}

$iterators = [
    generate([0,3,6]),
    generate([1,4,7]),
    generate([2,5,8])
];

$mi = new MergingIterator($iterators, function($a, $b){return $a-$b;});;

foreach($mi as $key => $item) {
    printf("%d\n", $item);
}