Skip to content

Latest commit

 

History

History

type_list

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

Type List

Array-like data structure with typed values. There are only typed values indexed by integer keys could be stored in the list. When you work with the list, you can be sure that all values are of the same type.

Usage

$mixedList = new MixedList(); // List with mixed values
$intList = new IntList(); // List with integer values
$floatList = new FloatList(); // List with float values
$stringList = new StringList(); // List with string values

// List with specified array and capacity
$intList = new IntList([1, 2, 3, 4, 5], 10);

// Invalid argument exception will be thrown
$intList = new IntList([1, 2, 3, 4, 5, '6']); // Invalid array
$stringList = new StringList([1, 2, 3, 4, 5], 3); // Invalid capacity

Available methods

Explain the methods available in StringList, but they are the same for all other classes with different value types.

appendValue

append(string $value): self

Appends a value to the array and increments the length.

get

get(int $index): string

Returns value at the given index. If the index is out of bounds, an exception will be thrown.

values

values(): string[]

Returns all the values.

replace

replace(int $index, string $value): self

Replaces the value at the given index.

remove

remove(int $index): self

Removes the value at the given index and decrements the length. If the index is out of bounds, throws an exception.

indexOf

indexOf(string $value): ?int

Returns the index of the first occurrence of the given value or null if not found.

has

has(string $value): bool

Checks if contains the given value.

hasAny

hasAny(string ...$values): bool

Checks if contains any of the given values.

hasAll

hasAll(string ...$values): bool

Checks if contains all the given values.

unique

unique(int $flags = SORT_STRING): self

Makes the array unique. Removes all null values from the array.

sort

sort(int $flags = SORT_REGULAR): self

Sorts the array using the given callback.

filter

filter(?callable $callback = null): self

Filters the array using the given callback. If the callback is null, removes all empty values from the array.

length

length(): int

Returns length of the array

capacity

capacity(): int

Returns capacity of the array

left

left(): int

Returns capacity left

isFull

clear(): void

Checks if array is full of data

isEmpty

isEmpty(): bool

Checks if array is empty