PHP code example of ideade / typed-collections

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

    

ideade / typed-collections example snippets


use Ideade\TypedCollections\TypedCollection;

final class ExampleCollection extends TypedCollection
{
    protected function valueType() : string
    {
        return Example::class;
    }
}


$collection = new ExampleCollection();

// Add an element
$collection->add(new Example());

// Get item by key
$collection->get(0);

// Add an element by key
$collection->addByKey(0, new Example());

// Delete element by key
$collection->remove(0);

// Set collection items (check the type of each item)
$collection->setItems([new Example(), new Example(), new Example()]);