1. Go to this page and download the library: Download zicht/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/ */
use function Zicht\Itertools\iterable;
$result = iterable($vehicles)->map('type');
var_dump($result);
// {0: 'car', 1: 'bike', 2: 'unicicle', 3: 'car'}
use function Zicht\Itertools\iterable;
$result = iterable($vehicles)->map('colors.2');
var_dump($result);
// {0: 'blue', 1: 'blue', 2: null, 3: null}
use function Zicht\Itertools\iterable;
$result = iterable($vehicles)->filter('is_cool')->mapBy('id')->map('type');
var_dump($result);
// {5: 'unicicle', 9: 'car'}
use function Zicht\Itertools\iterable;
$getTitle = fn($value, $key) => sprintf('%s with %s wheels', $value['type'], $value['wheels']);
$titles = iterable($vehicles)->map($getTitle);
var_dump($titles);
// {0: 'car with 4 wheels', ..., 3: 'car with 8 wheels'}
use function Zicht\Itertools\iterable;
$types = iterable($vehicles)->mapBy('id')->map('type');
var_dump($types);
// {1: 'car', 2: 'bike', 5: 'unicicle', 9: 'car'}
use Zicht\Itertools\util\Mappings;
use function Zicht\Itertools\iterable;
$lengths = iterable($words)->map(Mappings::length());
var_dump($lengths);
// {0: 6, 1: 3, 2: 4, 3: 5, 4: 9}
use function Zicht\Itertools\iterable;
$isExpensive = fn($value, $key) => $value['price'] >= 10000;
$expensiveTypes = iterable($vehicles)->filter($isExpensive)->map('type');
var_dump($expensiveTypes);
// {1: 'car', 9: 'car'}
use function Zicht\Itertools\iterable;
$coolVehicleTypes = iterable($vehicles)->filter('is_cool')->map('type');
var_dump($coolVehicleTypes);
// {5: 'unicicle', 9: 'car'}
use Zicht\Itertools\util\Filters;
use function Zicht\Itertools\iterable;
$movieWords = iterable($words)->filter(Filters::in(['Shining', 'My little pony', 'Goonies']));
var_dump($movieWords);
// {1: 'Goonies'}
use function Zicht\Itertools\iterable;
$ordered = iterable($numbers)->sorted();
var_dump($ordered);
// {0: 1, 2: 2, 1: 3, 4: 4, 3: 5}
use Zicht\Itertools\util\Mappings;
use function Zicht\Itertools\iterable;
$randomized = iterable($words)->sorted(Mappings::random());
var_dump($randomized);
// {... randomly ordere words ...}
use function Zicht\Itertools\iterable;
$vehiclesByType = iterable($vehicles)->groupBy('type');
var_dump($vehiclesByType);
// {'bike': {1: [...]}, 'car': {0: [...], 3: [...]} 'unicicle': {2: [...]}}
use function Zicht\Itertools\iterable;
$sum = iterable($numbers)->reduce();
var_dump($sum);
// 15
public static function add($a, $b): \Closure
{
return $a + $b;
}