PHP code example of thanhtaivtt / collection

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

    

thanhtaivtt / collection example snippets


use thanhtaivtt\Collection\Collection;

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

//or
Collection::init([1,2,3,6,4]);


    Collection::init([1, 2, 3])->sum();
    // 6

    Collection::init([1, 2, 3])->avg();
    // 2

    Collection::init([1, 2, 3])->min();
    // 1


    Collection::init([1, 2, 3])->max();
    // 1


    Collection::init([1, 2, 3])->all();
    // [1,2,3]


    $chunk = Collection::init([1, 2, 3])->chunk(2);
    $chunk->toArray();
    // [[1, 2], [3]]


    $chunk = Collection::init([1, 2, 3])->toArray();
    // [1, 2, 3]