1. Go to this page and download the library: Download oceanmoon/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/ */
oceanmoon / collections example snippets
// Restrict types at runtime
$numbers = new Sequence('int');
$numbers->append(1, 2, 3); // ✅ Works
$numbers->append('four'); // ❌ InvalidArgumentException
// Union types
$mixed = new Sequence('int|string');
$mixed->append(1, 'two', 3); // ✅ All work
// Type inference
$seq = new Sequence(source: [1, 2, 3]);
// Automatically infers type as 'int'
// PHP arrays: keys must be string|int
$array = [];
$array[new DateTime()] = 'event'; // ❌ Fatal error
$array[[1, 2]] = 'coords'; // ❌ Illegal offset
// Dictionary: any type works
$dict = new Dictionary();
$dict[new DateTime()] = 'event'; // ✅ Works
$dict[[1, 2, 3]] = 'coordinates'; // ✅ Works
$dict[fopen('file.txt', 'r')] = 'data'; // ✅ Works
$dict[true] = 'yes'; // ✅ Works
$dict[null] = 'empty'; // ✅ Works