1. Go to this page and download the library: Download jopic/php-streams 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/ */
jopic / php-streams example snippets
Stream::ofList(array(1, 2, 3))
->limit(1) // limits the stream to the first element
Stream::ofList(array(1, 2, 3))
->skip(1) // the resulting elements are (2, 3)
Stream::ofList(array(1, 2, 3, 4, 5))
->step(function($i) { return $i + 2; }); // will iterate over the following elements (1, 3, 5)
Stream::ofList(array(1, 2, 3, 4, 5))
->filter(function($item) { return $item % 2 == 0; }); // will filter the elements (2, 4)
Stream::ofList(array(1, 2, 3))
->map(function($item) { return $item + 1; })
->toArray(); // will return the array(2, 3, 4)