Download the PHP package mulertech/collections without Composer
On this page you can find all versions of the php package mulertech/collections. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mulertech/collections
More information about mulertech/collections
Files in mulertech/collections
Package collections
Short Description The MulerTech Collections package
License MIT
Informations about the package collections
Collections
This is a simple collections package for PHP. It provides a set of methods to work with arrays in a more functional way.
Installation
Two methods to install Collections package with composer :
1. Add to your "composer.json" file into require section :
and run the command :
2. Run the command :
Usage
__construct(array $items = []) : Initializes a new collection with the provided items.
all(callable $callback): bool : Checks if all items in the collection satisfy the callback.
any(callable $callback): bool : Checks if at least one item in the collection satisfies the callback.
arsort(int $sortFlags = SORT_REGULAR): void : Sorts the items in the collection in descending order while maintaining key association.
asort(int $sortFlags = SORT_REGULAR): void : Sorts the items in the collection in ascending order while maintaining key association.
changeKeyCase(int $case = CASE_LOWER): void : Changes the case of all keys in the collection.
chunk(int $length, bool $preserveKeys = false): array : Splits the collection into chunks of the specified size.
column(int|string|null $columnKey, int|string|null $indexKey = null): array : Returns the values from a single column of the collection.
combine(array $keys, array $values): void : Creates a new collection using the provided keys and values.
contains(mixed $value): bool : Checks if a value exists in the collection.
count(int $mode = COUNT_NORMAL): int : Counts the number of items in the collection.
countValues(): array : Counts the values of the collection.
current(): mixed : Returns the current item in the collection.
diff(array ...$arrays): array : Computes the difference between the collection and the provided arrays.
diffAssoc(array ...$arrays): array : Computes the difference with the provided arrays by comparing keys and values.
diffKey(array ...$arrays): array : Computes the difference with the provided arrays by comparing only keys.
diffUassoc(callable $callback, array ...$arrays): array : Computes the difference with the provided arrays using a callback function for keys.
diffUkey(callable $callback, array ...$arrays): array : Computes the difference with the provided arrays using a callback function for keys.
end(): mixed : Returns the last item in the collection.
extract(int $flags = EXTR_OVERWRITE, string $prefix = ''): int : Extracts variables from the collection.
fill(int $startIndex, int $count, mixed $value): void : Fills the collection with a specified value.
fillKeys(array $keys, mixed $value): void : Fills the collection with the specified keys and value.
filter(?callable $callback = null, int $mode = 0): void : Filters the items in the collection using a callback.
find(callable $callback): mixed : Finds the first item that satisfies the callback.
findKey(callable $callback): mixed : Finds the key of the first item that satisfies the callback.
flip(): void : Exchanges the keys and values of the collection.
getIterator(): Traversable : Returns an external iterator for the collection, allowing it to be used in foreach loops.
// Output: // Key: 0, Value: 1 // Key: 1, Value: 2 // Key: 2, Value: 3
inArray(mixed $needle, bool $strict = false): bool : Checks if a value exists in the collection.
intersect(array ...$arrays): array : Computes the intersection of the collection with the provided arrays.
intersectAssoc(array ...$arrays): array : Computes the intersection with the provided arrays by comparing keys and values.
intersectKey(array ...$arrays): array : Computes the intersection with the provided arrays by comparing only keys.
intersectUassoc(callable $callback, array ...$arrays): array : Computes the intersection with the provided arrays using a callback function for keys.
intersectUkey(callable $callback, array ...$arrays): array : Computes the intersection with the provided arrays using a callback function for keys.
isList(): bool : Checks if the collection is a list.
items(): array : Returns the items in the collection.
key(): int|string|null : Returns the key of the current item.
keyExists(mixed $key): bool : Checks if a key exists in the collection.
keyFirst(): int|string|null : Returns the first key of the collection.
keyLast(): int|string|null : Returns the last key of the collection.
keys(mixed $filterValue = null, bool $strict = false): array : Returns all keys in the collection.
krsort(int $sortFlags = SORT_REGULAR): void : Sorts the keys of the collection in descending order.
ksort(int $sortFlags = SORT_REGULAR): void : Sorts the keys of the collection in ascending order.
map(callable $callback, array ...$arrays): void : Applies a function to each item in the collection.
merge(array ...$arrays): void : Merges the collection with the provided arrays.
mergeRecursive(array ...$arrays): void : Recursively merges the collection with the provided arrays.
multisort(mixed $sortOrder = SORT_ASC, mixed $sortFlags = SORT_REGULAR, mixed ...$rest): void : Sorts the collection using multiple criteria.
natcasesort(): void : Sorts the collection using a case-insensitive natural order algorithm.
natsort(): void : Sorts the collection using a natural order algorithm.
next(): mixed : Advances the internal pointer of the collection and returns the next item.
pad(int $length, mixed $value): void : Pads the collection to the specified length with a value.
pop(): mixed : Pops and returns the last item of the collection.
prev(): mixed : Rewinds the internal pointer of the collection and returns the previous item.
product(): int|float : Computes the product of the values in the collection.
push(mixed ...$values): void : Pushes one or more items onto the end of the collection.
rand(int $num = 1): int|string|array : Selects one or more random items from the collection.
range(string|int|float $start, string|int|float $end, int|float $step = 1): void : Creates a collection containing a range of elements.
reduce(callable $callback, mixed $initial = null): mixed : Reduces the collection to a single value using a callback.
remove(int|string $key): void : Removes an item from the collection by its key.
removeItem(mixed $item, bool $strict = true): bool : Removes an item from the collection by its value and returns whether the item was found and removed.
replace(array ...$replacements): void : Replaces the items in the collection with the items from the provided arrays.
replaceRecursive(array ...$replacements): void : Recursively replaces the items in the collection with the items from the provided arrays.
reset(): mixed : Resets the internal pointer of the collection and returns the first item.
reverse(bool $preserveKeys = false): void : Reverses the order of the items in the collection.
rsort(int $sortFlags = SORT_REGULAR): void : Sorts the collection in descending order.
search(mixed $needle, bool $strict = false): int|string|false : Searches for a value in the collection and returns the corresponding key.
shift(): mixed : Shifts and returns the first item of the collection.
shuffle(): void : Shuffles the items in the collection.
slice(int $offset, ?int $length = null, bool $preserveKeys = false): array : Extracts a slice of the collection.
sort(int $sortFlags = SORT_REGULAR): void : Sorts the collection in ascending order.
splice(int $offset, ?int $length = null, mixed $replacement = []): void : Removes a portion of the collection and replaces it with the provided items.
sum(): int|float : Computes the sum of the values in the collection.
uasort(callable $callback): void : Sorts the collection using a user-defined comparison function.
udiff(callable $callback, array ...$arrays): array : Computes the difference between the collection and the provided arrays using a callback function.
udiffAssoc(callable $callback, array ...$arrays): array : Computes the difference with the provided arrays using a callback function for values.
udiffUassoc(callable $valueCallback, callable $keyCallback, array ...$arrays): array : Computes the difference with the provided arrays using callback functions for values and keys.
uintersect(callable $callback, array ...$arrays): array : Computes the intersection of the collection with the provided arrays using a callback function.
uintersectAssoc(callable $callback, array ...$arrays): array : Computes the intersection with the provided arrays using a callback function for values.
uintersectUassoc(callable $valueCallback, callable $keyCallback, array ...$arrays): array : Computes the intersection with the provided arrays using callback functions for values and keys.
uksort(callable $callback): void : Sorts the collection by keys using a user-defined comparison function.
unique(int $sortFlags = SORT_STRING): void : Removes duplicate values from the collection.
unshift(mixed ...$values): int : Unshifts one or more items onto the beginning of the collection.
usort(callable $callback): void : Sorts the collection using a user-defined comparison function.
values(): array : Returns all values in the collection.
walk(callable $callback, mixed $arg = null): void : Applies a function to each item in the collection.
walkRecursive(callable $callback, mixed $arg = null): void : Recursively applies a function to each item in the collection.
`