PHP Classes

File: README.md

Recommend this page to a friend!
  Classes of Kiril Savchev   ITE Collection   README.md   Download  
File: README.md
Role: Documentation
Content type: text/markdown
Description: readme file
Class: ITE Collection
Manage sets of arrays or objects as collections
Author: By
Last change:
Date: 7 years ago
Size: 1,615 bytes
 

Contents

Class file image Download

If-Then-Else Collection Library

Class set for collections

It contains two different types of collections - ArrayCollection and ObjectCollection. ArrayCollection stores unique values in array. ObjectCollection stores unique objects, instances of a given class.

Usage

    <?php
    // ArrayCollection usage:
    use Ite\Collection\ArrayCollection;

    $collection = new ArrayCollection();
    $collection->set(12);
    $collection->set("A");
    //var_dump($collection->toArray());
    $collection->set("B");
    //var_dump($collection->toArray());

    $collection2 = new ArrayCollection([1,44,'asd', 5 => PHP_INT_MAX]);
    $collection->merge($collection2);
    var_dump($collection->toArray());
    //$max = $collection->remove(PHP_INT_MAX);
    //var_dump($collection->toArray(), $max);
    foreach ($collection as $key => $val) {
            echo $key.': '.$val.PHP_EOL;
    }

    // ObjectCollection usage:
    use Ite\Collection\ObjectCollection;

    $collection = new ObjectCollection('\stdClass');
    $a = new stdClass();
    $b = new stdClass();
    $c = new stdClass();
    $d = new stdClass();
    $e = new stdClass();
    $collection->set($a);
    $collection->set($b);
    $collection->set($c);
    //$collection->set($c); -> throw exception
    $collection->set($d);
    $collection->set($e);
    foreach ($collection as $key => $val) {
            echo $key.': '.get_class($val).PHP_EOL;
    }