Steein Collections
Collection library for working with data., (*1)
Using Collection
use Steein\Common\Collections\Collection;
//Generated default array
$array = [
'name' => 'Shamsudin',
'project' => 'Steein',
'text' => 'default text',
'Cars' => [
'car_audi' => 'Audi',
'car_bwm' => 'Bmw'
]
];
//Default
$collection = new Collection($array);
//Or Static implementation
$collection = Collection::instance($array);
Available methods and implementation methods
In this documentation we will describe the most necessary methods, and all the rest, and you can see a lot of them in the code, everything is described there, (*2)
The magic method for creating and retrieving a new item for the collection, (*3)
$collection->new_array = 'value';
toArray(), (*4)
Getting the collections of elements in the Array format., (*5)
$collection->toArray()
toJson(), (*6)
Getting the collections of elements in the Json format., (*7)
$collection->toJson();
toXml(), (*8)
Getting the collections of elements in the Json format., (*9)
$collection->toXml();
set(), (*10)
New item for collection, (*11)
$collection->set('key', 'value');
get(), (*12)
Get the item from the collection by key., (*13)
$collection->get('key');
slice(), (*14)
Create the main array of the collection., (*15)
$collection->slice(1);
nth(), (*16)
Create a new collection of each n-th attribute., (*17)
$collection->nth(2);
union(), (*18)
Union of collections with these elements., (*19)
$new_collection = Collection::instance([0 => ['a'], 1 => ['b'], 2 => ['c']]);
$new_collection->union([3 => ['b'], 2 => ['c']]);
combine(), (*20)
Create a collection using this collection for keys, and the other for its values., (*21)
$new_collection = Collection::instance(['firstname','lastname','age']);
$new_collection->combine(['Shamsudin','Serderov', 22]);
merge(), (*22)
Combine the collection with these elements., (*23)
$new_collection = Collection::instance(['id_goods' => 100,'price' => 10000, 'instock' => 0]);
$new_collection->merge(['price' => 9550, 'count' => 1]);
isEmpty(), (*24)
Determine whether the collection is empty or not., (*25)
$collection->isEmpty();
isNotEmpty(), (*26)
Determine if the collection is empty., (*27)
$collection->isNotEmpty();
has(), (*28)
Determine if an element exists in the collection by key., (*29)
$collection->has('project');
forget(), (*30)
Remove an item from the collection by key., (*31)
$collection->forget('name');
archive(), (*32)
Archive the collection with one or more arrays., (*33)
$new_collection = Collection::instance(['test', 'test1']);
$new_collection->archive([50, 22]);
clear(), (*34)
Clearing Attributes in the Collection, (*35)
$collection->clear();
count(), (*36)
Count the number of items in the collection., (*37)
$collection->count()
flip(), (*38)
We turn the elements into collections., (*39)
$flip = $collection->flip();
$flip->all();
values(), (*40)
Get values from items in the collection, (*41)
$collection->values();
keys(), (*42)
Get the keys to the attributes of the collection., (*43)
$collection->keys();
indexOf(), (*44)
We search for a specific value in the collection, (*45)
$collection->indexOf('Shamsudin');
all(), (*46)
Get all attributes, (*47)
$collection->all();