1. Go to this page and download the library: Download talesoft/tale-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/ */
use Tale\Iterator\IterableIterator;
$values = new IterableIterator(['a', 'b', 'c', 'd', 'e']);
$filterer = new \RegexIterator($values, '/[a-c]/');
var_dump(iterator_to_array($filterer));
/*
array(3) {
[0] => string(1) "a"
[1] => string(1) "b"
[2] => string(1) "c"
}
*/
use Tale\Iterator\CallbackFilterIterator;
use Tale\Iterator\ValueIterator;
$values = new \ArrayIterator(range(0, 5));
$filterer = new CallbackFilterIterator($values, function (int $number) {
return $number !== 3;
});
$resetter = new ValueIterator($filterer);
var_dump(iterator_to_array($resetter));
/*
array(5) {
[0] => string(7) "Value 0"
[1] => string(7) "Value 1"
[2] => string(7) "Value 2"
[3] => string(7) "Value 4"
[4] => string(7) "Value 5"
}
Compare the output to the CallbackFilterIterator example above
and notice the keys!
*/
use Tale\Iterator\KeyIterator;
$values = new \ArrayIterator(['a' => 1, 'b' => 2, 'c' => 3]);
$keys = new KeyIterator($values);
var_dump(iterator_to_array($keys));
/*
array(3) {
[0] => string(1) "a"
[1] => string(1) "b"
[2] => string(1) "c"
}
Compare the output to the CallbackFilterIterator example above
and notice the keys!
*/
use Tale\Iterator\IndexIterator;
$values = new \ArrayIterator(['a' => 'b', 'b' => 'c', 'c' => 'd']);
$indexer = new IndexIterator($values);
foreach ($indexer as $key => $value) {
$i = $indexer->getIndex();
echo "{$key} => {$value} - at index: {$i}\n";
}
/*
a => b - at index: 0
b => c - at index: 1
c => d - at index: 2
*/
use Tale\Iterator\FlipIterator;
use Tale\Iterator\CallbackMapIterator;
$values = new \ArrayIterator(['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4]);
$mapper = new FlipIterator(
new CallbackMapIterator(
new FlipIterator($values),
function (string $key) {
return "Key {$key}";
}
)
);
var_dump(iterator_to_array($mapper));
/*
array(4) {
'Key a' => int(1)
'Key b' => int(2)
'Key c' => int(3)
'Key d' => int(4)
}
*/
use Tale\Iterator\FlipIterator;
use Tale\Iterator\CallbackFilterIterator;
$values = new \ArrayIterator(['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4]);
$mapper = new FlipIterator(
new CallbackFilterIterator(
new FlipIterator($values),
function (string $key) {
return $key !== 'b';
}
)
);
var_dump(iterator_to_array($mapper));
/*
array(4) {
'a' => int(1)
'c' => int(3)
'd' => int(4)
}
*/
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.