PHP Classes

How to Use a PHP Collection Class to Preform Useful Types of Operation Learning from the Package TCollection: Examples of processing collections of objects

Recommend this page to a friend!
  Info   Example   Screenshots   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2026-03-31 (3 days ago) RSS 2.0 feedNot yet rated by the usersTotal: Not yet counted Not yet ranked
Version License PHP version Categories
tcollection 1.0Custom (specified...8.4Data types, PHP 8
Description 

Author

This class provides example scripts of processing collections of objects.

It provides several scripts that call a class to process collections of objects.

Currently it provides example scripts for:

- Process collection elements accessing the collection with array access functions

- Compare two collections to determine which elements are different

- Perform average and sum calculations using collection elements

Picture of Christos Drogidis
  Performance   Level  
Name: Christos Drogidis <contact>
Classes: 37 packages by
Country: Greece Greece
Age: ???
All time rank: 379423 in Greece Greece
Week rank: 5 Up1 in Greece Greece Up
Innovation award
Innovation award
Nominee: 21x

Winner: 4x

Instructions

Example

<?php
/*
dobu {
    file:id(`example-00000096`) {
        ascoos {
            logo {`
                  __ _ ___ ___ ___ ___ ___ ___ ___
                 / _` |/ / / __/ _ \ / _ \ / / / _ \ / /
                | (_| |\ \| (_| (_) | (_) |\ \ | (_) |\ \
                 \__,_|/__/ \___\___/ \___/ /__/ \___/ /__/
            `},
            name {`ASCOOS OS`},
            version {`1.0.0`},
        },
        example {
            class {`TCollection`},
            methods {`TCollection ArrayAccess (offsetExists, offsetGet, offsetSet, offsetUnset)`},
            source {`kernel/core/tcollection/tcollection.array_access.php`},
            category:langs {
                en {`Objects Collection`},
                el {`??????? ????????????`}
            },
            summary:langs {
                en {`Using a collection like an array with offset`},
                el {`????? ???????? ??? array ?? offset`}
            },
            desc:langs {
                en {`Demonstrates array-like access using ArrayAccess interface.`},
                el {` ??????????? ???????? ????? array ???? interface ArrayAccess`}
            },
            author {`Drogidis Christos`},
            sincePHP {`8.4.0`}
        }
    }
}
*/
declare(strict_types=1);

use
Ascoos\OS\Kernel\Core\Collections\TCollection;

$startTime = microtime(true);
$startMem = memory_get_usage();

echo
"<h1>TCollection ArrayAccess</h1>";

// ????????????????????????????????????????????????
// <EN> Creating collection
// <EL> ?????????? ????????
// ????????????????????????????????????????????????
$collection = new TCollection();

// ????????????????????????????????????????????????
// <EN> offsetSet - adding with offset (like $collection['key'] = value)
// <EL> offsetSet - ???????? ?? offset (??? $collection['key'] = value)
// ????????????????????????????????????????????????
$collection['a'] = new stdClass();
$collection[10] = new stdClass();

// ????????????????????????????????????????????????
// <EN> offsetExists + offsetGet - existence check and retrieval
// <EL> offsetExists + offsetGet - ??????? ??????? ??? ????????
// ????????????????????????????????????????????????
echo "<h2>offsetExists + offsetGet - existence check and retrieval</h2>";
if (isset(
$collection['a'])) {
    echo
"<pre>"."The key 'a' exists\n"."</pre>";
   
$itemA = $collection['a'];
}

if (isset(
$collection[10])) {
    echo
"<pre>"."Key 10 exists\n"."</pre>";
}

// ????????????????????????????????????????????????
// <EN> offsetUnset - removal of an element (like unset($collection['key']))
// <EL> offsetUnset - ???????? ????????? (??? unset($collection['key']))
// ????????????????????????????????????????????????
echo "<h2>offsetUnset - removal of an element</h2>";
unset(
$collection['a']);

if (!isset(
$collection['a'])) {
    echo
"<pre>"."The key 'a' was removed\n"."</pre>";
}

// ????????????????????????????????????????????????
// <EN> Addition without key (push like array)
// <EL> ???????? ????? ?????? (push ??? array)
// ????????????????????????????????????????????????
echo "<h2>Addition without key (push like array)</h2>";
$collection[] = new stdClass(); // offsetSet with null offset -> add()

echo "<pre>"."Total elements after the changes: " . $collection->count() . "\n"."</pre>";

// ????????????????????????????????????????????????
// <EN> Memory cleanup
// <EL> ?????????? ??????
// ????????????????????????????????????????????????
$collection->Free();

echo
"Example completed.\n";

// ==================== STATISTICS ====================

print_stats($startTime, $startMem);
?>


Details

ASCOOS OS ? TCollection

A lightweight, object?only Deep Core collection class for the ASCOOS Web Operating System.

Ascoos

Overview

TCollection is a Deep Core class of the ASCOOS OS Kernel. It provides a simple, predictable, non?chainable collection structure that stores only objects (not arrays, not scalars).

It is designed for internal Kernel usage and for developers who need strict, object?based collections with optional type enforcement.

Implements:

  • ArrayAccess
  • Countable
  • IteratorAggregate
  • JsonSerializable

Features

  • ? Stores only objects
  • ? Optional strict type enforcement (`instanceof`)
  • ? Array?like access
  • ? Filtering, mapping, grouping
  • ? diff() & intersect()
  • ? JSON serialization
  • ? Deep Core Kernel class (always loaded)
  • ? Fully documented with DoBu

For array/data manipulation, use TArrayHandler instead.

Namespace

use Ascoos\OS\Kernel\Core\Collections\TCollection;

Basic Example

$users = new TCollection();

$user = new stdClass();
$user->name = 'John';

$users->add($user);

echo $users->count(); // 1

Typed Collections (via TCollector)

use Ascoos\OS\Kernel\Core\Collections\TCollector;

TCollector::register('user', App\Models\User::class);

$users = TCollector::create('user');

$users->add(new User()); // OK

Documentation

Full documentation (methods, parameters, examples, DoBu blocks) is available on the official ASCOOS OS website.

License

AGL (Ascoos General License)

Author

Drogidis Christos Creator of ASCOOS OS https://www.ascoos.com


Screenshots (3)  
  • examples/tcollection.array_access.png
  • examples/tcollection.diff_intersect.png
  • examples/tcollection.sum_avg.png
  Files folder image Files (11)  
File Role Description
Files folder imageexamples (3 files)
Files folder imagekernel (1 file)
Accessible without login Plain text file LICENSE-EL.md Lic. License text
Accessible without login Plain text file LICENSE.md Lic. License text
Accessible without login Plain text file README-EL.md Doc. Documentation
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (11)  /  examples  
File Role Description
  Accessible without login Plain text file tcollection.array_access.php Example Example script
  Accessible without login Plain text file tcollection.diff_intersect.php Example Example script
  Accessible without login Plain text file tcollection.sum_avg.php Example Example script

  Files folder image Files (11)  /  kernel  
File Role Description
  Accessible without login Plain text file coreCollections.php Aux. Configuration script

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
Downloadtcollection-2026-03-31.zip
Downloadtcollection-2026-03-31.tar.gz
Install with ComposerInstall with Composer
Needed packages  
Class DownloadWhy it is needed Dependency
Ascoos OS Download .zip .tar.gz Included in Ascoos OS Required
 Version Control Unique User Downloads  
 100%
Total:0
This week:0