PHP code example of team-a / collection

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

    

team-a / collection example snippets




$collection = new CarCollection($cars); 

$collection = $collection->sort(
    CarCollectionSorter::new()
        ->byModel()
        ->byColor()
);


$filter = CollectionFilter::new()
    ->withColor('blue')
    ->or(
        CarCollectionFilter::new()->withModel('408')
    )->or(
        CarCollectionFilter::new()->withVendor('VAZ')
    )
;

$hasAtLeastOneCar = $collection->has($filter);
$hasNoCars        = $collection->isEmpty($filter);
$hasDiscardedCars = $collection->hasNot($filter);

$firstCar = $collection->first($filter);
$lastCar  = $collection->last($filter);

$array = $collection->filter($filter)->asArray();
$count = $collection->count($filter);