PHP code example of tasoft / collection
1. Go to this page and download the library: Download tasoft/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/ */
tasoft / collection example snippets
$collection = new DefaultCollection(
[
"echo",
"alpha",
"delta",
"charlie",
"bravo"
]
);
$collection->sort([
new DefaultSortDescriptor(true) // Sort ascending
]);
print_r( $collection->toArray() ); // [alpha, bravo, charlie, delta, echo]
$collection = new TaggedCollection([1, 2, 3], /* accept duplicates */ true, /*case sensitive*/ true, /* tags ...*/ "test", "haha");
print_r($collection["test"]); // [1, 2, 3]
print_r($collection["unexisting tag"]); // NULL -- without notice
$collection = new PriorityCollection();
$collection->add(3, [5, 7]);
$collection->add(1, 8, 7);
$collection->add(7, 11, 3);
print_r($collection->toArray()); // [8, 7, [5, 7], 11, 3]
$collection = new DependencyCollection();
$collection->add('thomas', 1, ["Foo", 'Bar']);
$collection->add('Foo', 2);
$collection->add("Bar", 3, ["Foo"]);
$collection->add("Bettina", 6, ["thomas"]);
print_r($collection->getElementDependencies("thomas")); // [Foo, Bar]
print_r($collection->getOrderedElements());
/*
[
Foo => 1,
Bar => 3,
thomas => 1
Bettina => 6
]
*/