PHP code example of cocur / collection

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

    

cocur / collection example snippets


Cocur\Collection\CollectionInterface add(ItemInterface $item)

Iterator getIterator()

int count()

ItemInterface setCollection(CollectionInterface $collection)

CollectionInterface|null getCollection()

Item setValue(mixed $value)
mixed getValue()

Item create(mixed $value = null)

ArrayItem set(mixed $key, mixed $value)
bool has(mixed $key)
mixed get(mixed $key[, mixed $defaultValue])
ArrayItem remove(mixed $key()
array toArray()

ArrayItem createFromArray(array $data = [])

$item = ArrayItem::createFromArray(['foo' => 'bar');
$item['qoo'] = 'qoz';
echo count($item); // -> 2
if (isset($item['qoo'])) {
    echo $item['qoo']; // -> "qoz"
}

foreach ($item as $key => $value) {
    echo "$key: $value, ";
}
// -> "foo: bar, qoo: qoz, "