PHP code example of chh / itertools

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

    

chh / itertools example snippets




use itertools;

$users = new ArrayIterator(['John', 'Jim', 'Joe']);

foreach (itertools\slice($users, 1) as $user) {
    echo "$user\n";
}
# Output:
# Jim
# Joe



use itertools;

$a = new ArrayIterator(['one', 'two', 'three']);
$b = new ArrayIterator([1, 2, 3]);

$tuples = itertools\map(
    function($word, $number) {
        return [$word, $number];
    },
    $a, $b
);

foreach ($tuples as $t) {
    var_export($t);
}
# ['one', 1]
# ['two', 2]
# ['three', 3]



use itertools;

$a = new ArrayIterator(range(1, 10));

var_export(iterator_to_array(
    itertools\filter($a, function($value) {
        return $value >= 7;
    })
));
# Output:
# [7, 8, 9]