Skip to content

Iterable Collections with useful helper methods. Take control of your arrays!

License

Notifications You must be signed in to change notification settings

affinity4/collection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Affinity4 Collection

Iterable Collections with useful helper methods. Take control of your arrays!

Installation

composer require affinity4/collection

Usage

Standard Iteratable API

require_once __DIR__ '/vendor/autoload.php';

use Affinity4\Collection;

$Collection = new Collection([
    0 => 'one',
    1 => 'two',
    2 => 'three'
]);

$Collection->key(); // 0
$Collection->current(); // one
$Collection->valid(); // true

$Collection->next();
$Collection->key(); // 1
$Collection->valid(); // true
$Collection->current(); // two

$Collection->next();
$Collection->key(); // 2
$Collection->valid(); // true
$Collection->current(); // three

$Collection->next();
$Collection->key(); // 3
$Collection->valid(); // false

$Collection->prev();
$Collection->key(); // 2
$Collection->valid(); // true
$Collection->current(); // three

$Collection->rewind();
$Collection->key(); // 0
$Collection->valid(); // true
$Collection->current(); // one

Standard ArrayAccess API

require_once __DIR__ '/vendor/autoload.php';

use Affinity4\Collection;

$Collection = new Collection([
    0       => 'one',
    1       => 'two',
    2       => 'three',
    'one'   => 1,
    'two'   => 2,
    'three' => 3
]);

$Collection[0]; // one
$Collection[1]; // two
$Collection[2]; // three

$Collection['one'];   // 1
$Collection['two'];   // 2
$Collection['three']; // 3

About

Iterable Collections with useful helper methods. Take control of your arrays!

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages