Skip to content

ArrayCollection

Borrowed from ramsey/collection

Properties

items

The items of this array.

protected array $items

Methods

__construct

Constructs a new array object.

public __construct(array $items): mixed

Parameters:

Parameter Type Description
$items array The initial items to add to array.

type

Collection type.

protected type(): string

Inherited methods

__construct

Constructs a new array object.

public __construct(array $items): mixed

Parameters:

Parameter Type Description
$items array The initial items to add to array.

getIterator

Returns array as iterator.

public getIterator(): \Traversable

offsetExists

Returns true if the given offset exists in the array.

public offsetExists(mixed $offset): bool

Parameters:

Parameter Type Description
$offset mixed The offset to check.

offsetGet

Returns the value at the specified offset.

public offsetGet(mixed $offset): mixed

Parameters:

Parameter Type Description
$offset mixed The offset for which a value should be returned.

Return Value:

The value stored at the offset, or null if the offset does not exist.


offsetSet

Sets the given value to the given offset in the array.

public offsetSet(mixed $offset, mixed $value): void

Parameters:

Parameter Type Description
$offset mixed The offset to set.
$value mixed The value to set at the given offset.

Throws:


offsetUnset

Removes the given offset and its value from the array.

public offsetUnset(mixed $offset): void

Parameters:

Parameter Type Description
$offset mixed The offset to remove from the array.

serialize

Returns a JSON string.

public serialize(): string

unserialize

Converts a serialized string representation into an instance object.

public unserialize(array $items): void

Parameters:

Parameter Type Description
$items array A PHP array to unserialize.

count

Total number of collections.

public count(): int

clear

Removes all items from array instance.

public clear(): void

toArray

Returns an instance as an array.

public toArray(): array

isEmpty

Returns true if array is empty.

public isEmpty(): bool

extractValue

Extracts the value of the given property or method from the object.

protected extractValue(mixed $object, string|null $propertyOrMethod = null): mixed

Parameters:

Parameter Type Description
$object mixed The object to extract the value from.
$propertyOrMethod string|null The property or method for which the
value should be extracted.

Return Value:

the value extracted from the specified property or method.

Throws:

if the method or property is not defined.


toolValueToString

Returns a string representation of the value.

protected toolValueToString(mixed $value): string
  • null value: 'NULL'
  • boolean: 'TRUE', 'FALSE'
  • array: 'Array'
  • scalar: converted-value
  • resource: '(type resource #number)'
  • object with __toString(): result of __toString()
  • object DateTime: ISO 8601 date
  • object: '(className Object)'
  • anonymous function: same as object

Parameters:

Parameter Type Description
$value mixed the value to return as a string.

checkType

Returns true if value is of specified type.

protected checkType(string $type, mixed $value): bool

Parameters:

Parameter Type Description
$type string
$value mixed

add

Add an item to the collection.

public add(mixed $item): $this

Parameters:

Parameter Type Description
$item mixed

getType

Returns the type of the collection.

public getType(): string

contains

Returns true if this collection contains the specified element.

public contains(mixed $element, bool $strict = true): bool

Parameters:

Parameter Type Description
$element mixed The element to check whether the collection contains.
$strict bool Whether to perform a strict type check on the value.

map

Returns a new instance of the collection with the callback function $callable applied to each item

public map(callable $callable): $this

Parameters:

Parameter Type Description
$callable callable

each

Applies the callback function $callable to each item in the collection.

public each(callable $callable): $this

Parameters:

Parameter Type Description
$callable callable

flip

Flip the items in the collection.

public flip(): static

filter

Filter the collection items through the callable.

public filter(callable $callable): \Qubus\Support\Collection\BaseCollection

Parameters:

Parameter Type Description
$callable callable

get

Get the specified item from the collection.

public get(mixed $key): mixed

Parameters:

Parameter Type Description
$key mixed

Throws:


slice

Slice the underlying collection array.

public slice(int $offset, int|null $length = null): static

Parameters:

Parameter Type Description
$offset int
$length int|null

nth

Create a new collection consisting of every n-th element.

public nth(int $step, int $offset): static

Parameters:

Parameter Type Description
$step int
$offset int

reject

Reject the collection items through the callable.

public reject(callable $callable): \Qubus\Support\Collection\Collection|\Qubus\Support\Collection\BaseCollection

Parameters:

Parameter Type Description
$callable callable

push

Push an item to the collection.

public push(mixed $value): \Qubus\Support\Collection\BaseCollection

Parameters:

Parameter Type Description
$value mixed

put

Put the specified item in the collection with the given key.

public put(mixed $key, mixed $value): \Qubus\Support\Collection\BaseCollection

Parameters:

Parameter Type Description
$key mixed
$value mixed

values

Returns a new Collection instance containing an indexed array of values.

public values(): self

flatten

Returns a new Collection instance containing a flattened array of items.

public flatten(): self

sort

Sort the collection of item values through a user-defined comparison function.

public sort(callable|null $callback = null): static

Parameters:

Parameter Type Description
$callback callable|null

sortByKey

Sort the collection of item keys through a user-defined comparison function.

public sortByKey(callable|null $callback = null): static

Parameters:

Parameter Type Description
$callback callable|null

reverse

Reverse the collection items.

public reverse(): static

Search the collection for a given value and return the corresponding key if successful.

public search(mixed $value, bool $strict = false): string|int|bool

Parameters:

Parameter Type Description
$value mixed
$strict bool

groupBy

Group an associative array by a field or using a callback.

public groupBy(callable $callback): static

Parameters:

Parameter Type Description
$callback callable

keys

Returns a new Collection instance containing an indexed array of keys.

public keys(): self

all

Returns all items in collection.

public all(): array

pop

Get and remove the last item from the collection.

public pop(): mixed|null

last

Get the last item from the collection.

public last(): mixed|null

shift

Get and remove the first item from the collection.

public shift(): mixed|null

first

Get the first item from the collection.

public first(): mixed|null

sum

Get the sum of the collection items.

public sum(mixed|null $callback = null): int|float

Parameters:

Parameter Type Description
$callback mixed|null

merge

Merge items with current collection.

public merge(array $items): static

Parameters:

Parameter Type Description
$items array

Throws:


column

Returns the values from the given property or method.

public column(string $propertyOrMethod): array

Parameters:

Parameter Type Description
$propertyOrMethod string The property or method name to filter by.

Throws:


replace

Replace the collection items with the given items.

public replace(array $items): static

Parameters:

Parameter Type Description
$items array

replaceRecursive

Recursively replace the collection items with the given items.

public replaceRecursive(array $items): static

Parameters:

Parameter Type Description
$items array

type

Collection type.

protected type(): string
  • This method is abstract.

items

Returns an array of collections.

public items(): array


Automatically generated on 2025-10-13