1. Go to this page and download the library: Download hguenot/phpstream 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/ */
hguenot / phpstream example snippets
// Create a simple array of data
$array = [ -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ];
// Creates a Stream based on the previous array
$stream = new \phpstream\Stream($array);
// Compute the opposite value of each value
$stream = $stream->map(function($value){
return intval($value) * (-1);
});
// Get only odd values
$stream = $stream->filter(function($value){
return (intval($value) % 2) == 0;
});
// Collects data into an array
$new_array = $stream->collect(new \phpstream\collectors\ListCollector());
// Computes sum of all elements
$sum = $stream->reduce(function($a, $b){
return intval($a) + intval($b);
}, 0);