PHP code example of asko / collection

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

    

asko / collection example snippets


use Asko\Collection\Collection;

$collection = new Collection([1, 2, 3, 4, 5]);

$collection->push(6);

$collection->filter(function ($item) {
    return $item > 3;
});

$collection->map(function ($item) {
    return $item * 2;
});

$collection->any(function ($item) {
    return $item > 3;
});

$collection->all(function ($item) {
    return $item > 3;
});

$collection->each(function ($item) {
    echo $item;
});

$collection->reduce(function ($acc, $item) {
    return $acc + $item;
}, 0);

$collection->first();

$collection->last();

$collection->avg(function ($item) {
    return $item * 2;
});

$collection->sum(function ($item) {
    return $item * 2;
});

$collection->count();

$collection->toArray();