PHP code example of assegaiphp / collections
1. Go to this page and download the library: Download assegaiphp/collections 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/ */
assegaiphp / collections example snippets
use Assegai\Collections\Collection;
$collection = new Collection();
$collection->add(1);
$collection->add(2);
$collection->add(3);
$filteredCollection = $collection->filter(function($item) {
return $item > 1;
});
$mappedCollection = $collection->map(function($item) {
return $item * 2;
});
$sum = $collection->reduce(function($carry, $item) {
return $carry + $item;
}, 0);