PHP code example of rubicon / collection

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

    

rubicon / collection example snippets


$collection = new Collection([1, 2, 3]);
$result = $collection
	->map(function($item) {
        return $item * 2;
    })
    ->reduce(function($carry, $item) {
        return $item + $carry;
    });
    
echo $result; // 12