PHPackages                             multihanded/typed-array - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. multihanded/typed-array

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

multihanded/typed-array
=======================

Typed array implementation class for PHP.

1.0.1(1mo ago)02↓50%MITPHPPHP &gt;=8.0

Since Jun 15Pushed 1mo agoCompare

[ Source](https://github.com/YakutD/typed-array)[ Packagist](https://packagist.org/packages/multihanded/typed-array)[ RSS](/packages/multihanded-typed-array/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependencies (1)Versions (3)Used By (0)

TypedArray
==========

[](#typedarray)

The abstract `TypedArray` class implements typed arrays in PHP with strict type checking. The class implements the `Iterator`, `ArrayAccess`, and `Countable` interfaces, allowing you to work with the object as with a regular array.

Features
--------

[](#features)

- **Strong Typing**: All values ​​are checked against the type returned by the `getType()` method via [get\_debug\_type](https://www.php.net/manual/en/function.get-debug-type.php).
- **Fixed Length**: Option to prevent array resizing.
- **Nesting**: Support for multidimensional typed arrays.
- **Rich API**: Methods for filtering, sorting, searching, transforming, and other array operations.

How to install
--------------

[](#how-to-install)

You can install the package with the composer:

```
composer require multihanded/typed-array

```

Public Methods
--------------

[](#public-methods)

> **Note:** All class methods are provided with full PHPDoc blocks describing their parameters, return values, and thrown exceptions. Detailed information about each method is available directly in your IDE using autocompletion or by hovering over it.

### Abstract Methods

[](#abstract-methods)

MethodDescription`static getType(): string`An abstract method that must be implemented in the derived class and returns a string with the expected data type.### Constructor and Instance Creation

[](#constructor-and-instance-creation)

MethodDescription`__construct(array $initialArray = [], bool $fixedLength = false)`Constructor. Accepts an initial array and a fixed-length flag.`static fill(int $start_index, int $count, mixed $value): static`Creates a new instance filled with the specified value for the index range. If `$count` is greater than the array length or less than 0, a `ValueError` is thrown.`static fillKeys(array $keys, mixed $value): static`Creates a new instance filled with a value using the array of keys.`static combine(array $keys, array $values): static`Creates an instance using one array for keys and another for values.### Basic Operations

[](#basic-operations)

MethodDescription`set(mixed $value, string|int|null $key = null): $this`Sets the value by key (or appends to the end of the array). Returns the current instance.`plain(): array`Converts the inner collection to a regular PHP array.`plainRecursive(?int $depth = null): array`Recursively converts nested collections to a regular array. If `$depth = null` (the default), all possible nesting levels are traversed. If `$depth` is specified as a number, the conversion is limited to the specified number of levels.`count(): int`Returns the number of elements (`interface Countable`).`isFixedLength(): bool`Checks if the array's length is fixed.`fixLength(): $this`Fixes the array's length, preventing it from changing. Returns the current instance.### Iteration and Element Access

[](#iteration-and-element-access)

MethodDescription`rewind(): void`Resets the internal pointer (`interface Iterator`).`current(): mixed`Returns the current element (`interface Iterator`).`key(): mixed`Returns the current key (`interface Iterator`).`next(): void`Moves the pointer forward (`interface Iterator`).`valid(): bool`Checks if the current position (`interface Iterator`) is valid.`prev(): void`Moves the pointer to the previous element.`end(): void`Moves the pointer to the last element.`offsetExists(mixed $offset): bool`Checks if a key exists (`interface ArrayAccess`).`offsetGet(mixed $offset): mixed`Returns the value by key (`interface ArrayAccess`).`offsetSet(mixed $offset, mixed $value): void`Sets the value (`interface ArrayAccess`).`offsetUnset(mixed $offset): void`Removes an element by key (`interface ArrayAccess`).### Checking and Searching

[](#checking-and-searching)

MethodDescription`all(callable $callback): bool`Checks whether all elements satisfy the callback function.`any(callable $callback): bool`Checks whether at least one element satisfies the callback function.`find(callable $callback, bool $findKey = false): mixed`Returns the first element (or its key) that satisfies the callback.`isList(): bool`Checks whether the array is a list (keys are numbered sequentially starting from 0).`keyExists(string|int $key): bool`Checks whether a key exists.`keyFirst(): int|string|null`Returns the first key of the array.`keyLast(): int|string|null`Returns the last key of the array.`keys(mixed $filterValue): array`Returns keys that contain the specified value.`first(): mixed`Returns the first value of the array.`last(): mixed`Returns the last value of the array.`inArray(mixed $needle): bool`Checks if a value is in the array.`search(mixed $needle): int|string|false`Searches for a value and returns the first matching key.### Conversion and Modification (Immutable)

[](#conversion-and-modification-immutable)

> **Important**: All methods in this section return a **new instance** of the class with `fixedLength = false`.

#### Intersections and Divergences

[](#intersections-and-divergences)

MethodDescription`diff(TypedArray $array, TypedArray ...$arrays): static`Calculates the difference between arrays. **Important:** All passed `TypedArray` instances must be instances of the same class as the caller. Attempting to pass an array of a different type will result in a `TypeError`.`diffAssoc(TypedArray $array, TypedArray ...$arrays): static`Calculates the difference with additional index checking. **Important:** All passed `TypedArray` must be instances of the same class as the caller. Attempting to pass an array of a different type will result in a `TypeError`.`diffUassoc(callable $key_compare_func, TypedArray $array, TypedArray ...$arrays): static`Calculates the difference by checking indices via a callback.`diffKey(TypedArray $array, TypedArray ...$arrays): static`Calculates the difference using the keys for comparison. **Important:** All passed `TypedArray` must be instances of the same class as the caller. Attempting to pass an array of a different type will result in a `TypeError`.`diffUkey(callable $key_compare_func, TypedArray $array, TypedArray ...$arrays): static`Calculates the difference between keys via a callback. **Important:** All passed `TypedArray` must be instances of the same class as the caller. Attempting to pass an array of a different type will result in a `TypeError`.`udiff(callable $value_compare_func, TypedArray $array, TypedArray ...$arrays): static`Calculates the difference via a callback for comparing values. **Important:** All passed `TypedArray` must be instances of the same class as the caller. Attempting to pass an array of a different type will result in a `TypeError`.`udiffAssoc(callable $value_compare_func, TypedArray $array, TypedArray ...$arrays): static`Calculates the difference by checking indices via a callback for values. **Important:** All passed `TypedArray` must be instances of the same class as the caller. Attempting to pass an array of a different type will result in a TypeError.`udiffUassoc(callable $value_compare_func, callable $key_compare_func, TypedArray $array, TypedArray ...$arrays): static`Computes the difference via a callback for values ​​and keys. **Important:** All passed `TypedArray` must be instances of the same class as the caller. Attempting to pass an array of a different type will result in a TypeError.`intersect(TypedArray $array, TypedArray ...$arrays): static`Computes the intersection of arrays. **Important:** All passed `TypedArray` must be instances of the same class as the caller. Attempting to pass an array of a different type will result in a TypeError.`intersectAssoc(TypedArray $array, TypedArray ...$arrays): static`Computes the intersection with additional index checking. **Important:** All passed `TypedArray` must be instances of the same class as the caller. Attempting to pass an array of a different type will result in a `TypeError`.`intersectUassoc(callable $key_compare_func, TypedArray $array, TypedArray ...$arrays): static`Computes the intersection with index checking via the callback. **Important:** All passed `TypedArray` must be instances of the same class as the caller. Attempting to pass an array of a different type will result in a `TypeError`.`intersectKey(TypedArray $array, TypedArray ...$arrays): static`Computes the intersection using keys. **Important:** All passed `TypedArray` must be instances of the same class as the caller. Attempting to pass an array of a different type will result in a TypeError.`intersectUkey(callable $key_compare_func, TypedArray $array, TypedArray ...$arrays): static`Computes the intersection of keys via the callback. **Important:** All passed `TypedArray` must be instances of the same class as the caller. Attempting to pass an array of a different type will result in a TypeError.`uintersect(callable $value_compare_func, TypedArray $array, TypedArray ...$arrays): static`Computes the intersection of values ​​via the callback. **Important:** All passed `TypedArray` must be instances of the same class as the caller. Attempting to pass an array of a different type will result in a TypeError.`uintersectAssoc(callable $value_compare_func, TypedArray $array, TypedArray ...$arrays): static`Computes the intersection by checking the indices via a callback for values. **Important:** All passed `TypedArray` must be instances of the same class as the caller. Attempting to pass an array of a different type will result in a `TypeError`.`uintersectUassoc(callable $value_compare_func, callable $key_compare_func, TypedArray $array, TypedArray ...$arrays): static`Computes the intersection via a callback for values ​​and keys. **Important:** All passed `TypedArray` must be instances of the same class as the caller. Attempting to pass an array of a different type will result in a `TypeError`.#### Other Methods

[](#other-methods)

MethodDescription`changeKeyCase(int $case = CASE_LOWER): static`Changes the case of all keys.`countValues(): array`Counts the number of occurrences of each value.`filter(?callable $callback = null, int $mode = 0): static`Filters elements using a callback function. If `$callback` is not passed, all [empty](https://www.php.net/manual/en/function.empty.php) elements will be removed from the array.`map(callable $callback): static`Applies a callback to all elements.`pad(int $length, mixed $value): static`Pads an array to the specified length with a value.`merge(TypedArray $array, TypedArray ...$arrays): static`Merges multiple arrays. **Important:** All `TypedArray` passed must be instances of the same class as the caller. Attempting to pass an array of a different type will result in a `TypeError`.`mergeRecursive(TypedArray $array, TypedArray ...$arrays): static`Recursively merges arrays. Continues until it reaches elements that **do not implement** `TypedArray`. **Important:** All `TypedArray` passed must be instances of the same class as the caller. Attempting to pass an array of a different type will result in a `TypeError`.`replace(TypedArray $array, TypedArray ...$arrays): static`Replaces the values ​​of the current array with the values ​​from the passed arrays (keys from the passed arrays replace keys in the current array). **Important:** All passed `TypedArray` must be instances of the same class as the caller. Attempting to pass an array of a different type will result in a `TypeError`.`replaceRecursive(TypedArray $array, TypedArray ...$arrays): static`Recursively replaces values. Goes deeper until it reaches elements that **do not implement** `TypedArray`. **Important:** All passed `TypedArray` must be instances of the same class as the caller. Attempting to pass an array of a different type will result in a `TypeError`.`reverse(bool $preserveKeys = false): static`Returns the array in reverse order.`slice(int $offset, ?int $length = null, bool $preserveKeys = false): static`Extracts a slice of the array.`unique(): static`Removes duplicate values.`values(): static`Returns all values ​​in the array.### Modifying the Current Instance (Mutable)

[](#modifying-the-current-instance-mutable)

> **Important**: All methods in this section return the **current instance** (`$this`) for chaining purposes.

#### Sorting

[](#sorting)

MethodDescription`arsort(int $flags = SORT_REGULAR): $this`Sorts in descending order, preserving keys.`asort(int $flags = SORT_REGULAR): $this`Sorts in ascending order, preserving keys.`krsort(int $flags = SORT_REGULAR): $this`Sorts by keys in descending order.`ksort(int $flags = SORT_REGULAR): $this`Sorts by keys in ascending order.`natcasesort(): $this`Sorts using the "natural order" algorithm (case-insensitive).`natsort(): $this`Sorts using the "natural order" algorithm.`rsort(int $flags = SORT_REGULAR): $this`Sorts in descending order.`sort(int $flags = SORT_REGULAR): $this`Sorts in ascending order.`uasort(callable $callback): $this`Sorts while preserving keys, using callback for comparison.`uksort(callable $callback): $this`Sorts by keys, using callback for comparison.`usort(callable $callback): $this`Sorts by values, using callback for comparison.`multisort(TypedArray|int $param, TypedArray|int ...$params): $this`Sorts the collection along with other `TypedArray` objects.`shuffle(): $this`Shuffles the array randomly.#### Other Methods

[](#other-methods-1)

MethodDescription`pop(): mixed`Removes and returns the last element.`push(mixed ...$values): int`Adds one or more values ​​to the end of the array.`shift(): mixed`Removes and returns the first element.`unshift(mixed ...$values): int`Adds one or more values ​​to the beginning of the array.`walk(callable $callback, mixed $arg = null): $this`Applies a custom function to each element.`walkRecursive(callable $callback, mixed $arg = null): $this`Recursively applies a user-defined function until it reaches elements that **do not implement** `TypedArray`.### Calculating sums, products, and more

[](#calculating-sums-products-and-more)

MethodDescription`sum(): int|float`Calculates the sum of all values.`product(): int|float`Calculates the product of all values.`reduce(callable $callback, mixed $initial = null): mixed`Iteratively reduces an array to a single value.`rand(int $num = 1): int|string|array`Selects one or more random keys. If the array is empty, or `$num` is greater than the array length or less than 1, a `ValueError` is thrown.`flip(): array`Swaps all keys with their values ​​(returns a regular array).### Working with Nesting

[](#working-with-nesting)

#### General Methods

[](#general-methods)

MethodDescription`canDeepen(): bool`Determines whether it is possible to go deeper to the next level of nesting.`static isNestedArray(): bool`Checks whether the current type represents a nested structure.`depth(): int`Calculates the actual nesting depth based on the contents.#### Specialized Methods

[](#specialized-methods)

> **Important**: The following methods work **only with the first level of nesting** and require that the current instance be a **multi-level typed array**.

MethodDescription`flat(): TypedArray`Collapses nested first-level collections into a single typed array, discarding keys.`column(int|string|null $column_key, int|string|null $index_key = null): TypedArray`Returns values ​​from a single first-level column of a nested collection.`zip(): static`Zips nested first-level arrays, truncating the output to the length of the shortest array.`chunk(int $length): static`Concatenates first-level arrays and then splits them into chunks of the specified length. Keys are not preserved. If `$length` &lt; 1, a `ValueError` is thrown.Example of use
--------------

[](#example-of-use)

```
class IntArray extends TypedArray
{
    public static function getType(): string
    {
        return 'int';
    }
}

class NestedIntArray extends TypedArray
{
    public static function getType(): string
    {
        return IntArray::class;
    }
}

$typedArray = new NestedIntArray([
    new IntArray([1, 2, 3]),
    new IntArray([4, 5, 6]),
    new IntArray([7, 8, 9]),
]);

print_r($typedArray->walkRecursive(fn(&$val) => $val *= 2)->flat()->plain()); // [2, 4, 6, 8, 10, 12, 14, 16, 18]
```

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance90

Actively maintained with recent releases

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

45d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/23060971?v=4)[Daniil Egorov](/maintainers/YakutD)[@YakutD](https://github.com/YakutD)

---

Top Contributors

[![YakutD](https://avatars.githubusercontent.com/u/23060971?v=4)](https://github.com/YakutD "YakutD (2 commits)")

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/multihanded-typed-array/health.svg)

```
[![Health](https://phpackages.com/badges/multihanded-typed-array/health.svg)](https://phpackages.com/packages/multihanded-typed-array)
```

###  Alternatives

[violuke/php-barcodes

A collection of PHP classes for managing barcodes.

39600.0k7](/packages/violuke-php-barcodes)[fab2s/souuid

Simple Ordered Uuid Generator in PHP

13613.7k1](/packages/fab2s-souuid)[millerphp/laravel-browserless

This is my package laravel-browserless

1216.2k](/packages/millerphp-laravel-browserless)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
