PHP code example of escapio / php-iterables

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

    

escapio / php-iterables example snippets


$double_iterable = map($iterable_of_numbers, fn($number) => $number * 2);

$filtered_iterable = filter($iterable_of_numbers, fn($number) => $number < 5);

$iterable = function () {
    yield 1;
    yield 2;
}
toArray($iterable); // [1, 2]

(new \Escapio\Iterables\Builder())
  ->from(['Alice', 'Bob', 'Chuck'])
  ->map(strtolower(...))
  ->filter(fn ($name) => $name !== 'chuck')
  ->loop(function ($name) {
    echo $name . PHP_EOL;
  });
  // "alice"
  // "bob"