PHP code example of bentools / rewindable-generator
1. Go to this page and download the library: Download bentools/rewindable-generator 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/ */
bentools / rewindable-generator example snippets
$generator = (function () {
yield 'foo';
yield 'bar';
})();
var_dump(iterator_to_array($generator)); // ['foo', 'bar']
var_dump(iterator_to_array($generator)); // Boom
use BenTools\RewindableGenerator;
$generator = (function () {
yield 'foo';
yield 'bar';
})();
$iterator = new RewindableGenerator($generator);
var_dump(iterator_to_array($iterator)); // ['foo', 'bar']
var_dump(iterator_to_array($iterator)); // ['foo', 'bar']