PHP code example of ebidtech / collection

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

    

ebidtech / collection example snippets





use EBT\Collection\CollectionDirectAccessInterface;
use EBT\Collection\CountableTrait;
use EBT\Collection\DirectAccessTrait;
use EBT\Collection\EmptyTrait;
use EBT\Collection\GetItemsTrait;
use EBT\Collection\IterableTrait;

/**
 * TestCollection
 */
class TestCollection implements CollectionDirectAccessInterface
{
    use CountableTrait;
    use DirectAccessTrait;
    use EmptyTrait;
    use GetItemsTrait;
    use IterableTrait;

    /**
     * @var array
     */
    protected $items = array(
        'test1' => 'val1',
        'test2' => 'val2',
        'test3' => 'val3'
    );
}

$collection = new TestCollection();
echo count($collection); // will print 3
echo $collection->get('test1');  // will print val1
foreach ($collection as $key => $val) {
    // will result in:
    // test1 val1
    // test2 val2
    // test3 val3
    echo sprintf("%s %s", $key, $val);
}