PHP code example of marcegarba / funccoll
1. Go to this page and download the library: Download marcegarba/funccoll 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/ */
marcegarba / funccoll example snippets
use Marcegarba\FuncColl\Collection;
$sum = Collection::fromArray(range(1, 10))
->filter(function ($elem) { return $elem % 2 != 0; })
->take(3)
->map(function ($elem) { return $elem * 2; })
->reduce(function ($acc, $num) { return $acc + $num; });
echo $sum; // Outputs 18
use Marcegarba\FuncColl\Collection;
$pdo = new PDO(...);
$stmt = $pdo->query('SELECT * from items');
$generator = function () use ($stmt) {
return $stmt->fetch(PDO_ASSOC);
}
$items =
Collection::generate($generator, 100)
->map(function ($row) { return new Item($row); });