PHPackages                             reptily/array-list - 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. reptily/array-list

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

reptily/array-list
==================

ArrayList for PHP

0.2.2(2y ago)114GPL-3.0-or-laterPHPPHP ^7.3|^8.0

Since Oct 25Pushed 2y ago1 watchersCompare

[ Source](https://github.com/reptily/array-list)[ Packagist](https://packagist.org/packages/reptily/array-list)[ RSS](/packages/reptily-array-list/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (1)Versions (7)Used By (0)

Install
=======

[](#install)

```
composer require reptily/array-list
```

what problem does this library solve?
-------------------------------------

[](#what-problem-does-this-library-solve)

There are no built-in mechanisms for creating lists in the PHP language. An associative array does not guarantee that its elements are typed.

Example

```
function show(array $items)
{
    foreach ($items as $item) {
        echo $item->id . PHP_EOL;
    }
}
```

In this example, we do not guarantee that all elements will be the necessary objects, and we also do not guarantee that the array will be without attachments.

```
function show(ArrayList $items)
{
    foreach ($items as $item) {
        echo $item->id . PHP_EOL;
    }
}
```

The code did not become larger, but typification appeared. **ArrayList** takes care of all typing and data access issues. We can be sure that all types in the array are correct and not do unnecessary checks.

Example
-------

[](#example)

More examples in the directory [/example](/example)

#### Only integer

[](#only-integer)

```
$list = new ArrayList(ArrayList::TYPE_INTEGER, [1, 2, 3]);
// or
$list = new ArrayListInteger([1, 2, 3]);

foreach ($list as $item) {
    echo $item . PHP_EOL;
}
```

#### If we need a collection of objects

[](#if-we-need-a-collection-of-objects)

```
class UserList extends ArrayList {
    public function __construct(?array $items = null)
    {
        parent::__construct(UserDTO::class, $items);
    }
};

class UserDTO {
    public $id;
    public $name;

    public function __construct($id, $name)
    {
        $this->id = $id;
        $this->name = $name;
    }
}

$userList = new UserList();
$userList->add(new UserDTO(1, 'bob'));
$userList->add(new UserDTO(2, 'job'));

function echoDTOs(UserList $list): void
{
    $list->forEach(function ($item) {
        echo sprintf("id:%d name:%s" . PHP_EOL, $item->id, $item->name);
    });
}
```

#### Use as Object

[](#use-as-object)

```
$ids = new ArrayListInteger([1, 2, 3]);
$ids->add(4);

function show(ArrayListInteger $ids)
{
    $ids->forEach(function($id) {
        echo $id . PHP_EOL;
    });
}
show();
```

#### Use as Array

[](#use-as-array)

```
$ids = new ArrayListInteger([1, 2, 3]);
$ids[] = 4;

function show(ArrayListInteger $ids)
{
    foreach ($ids as $id) {
        echo $id;
    }
}
show();
```

### Methods

[](#methods)

**add(mixed $item): void**

Adds an element to the array

**count(): int**

Return the number of elements in the array

**isEmpty(): bool**

Return is empty

**indexOf(mixed $element): ?int**

Searches the array for a match, if there is one it will return the index, if not then return null

**lastIndexOf(): ?int**

Will return the last index in the array, if the array is empty will return null

**clone(): self**

Clones an object

**toArray(): array**

Converts to an associative array

**get(int $index): mixed**

Returns an element by its index, if there is no element, an exception will be thrown

**set(int $index, mixed $item): void**

Sets a value on an element by its index

**exists(int $index): bool**

Checks the presence of an element by its index

**remove(int $index): void**

Remove element by its index

**clear(): void**

Cleans the array

**forEach(): callback(mixed $item, int $index)**

Returns a callback for each element in the array

**sort(string $sort = 'asc'|'desc'): void**

Sorts an array

### Support class

[](#support-class)

**ArrayListInteger**

Creates a list where the elements must all be integer

**ArrayListString**

Creates a list where the elements must all be string

**ArrayListFloat**

Creates a list where the elements must all be float

Constants
---------

[](#constants)

Constants by types

- TYPE\_STRING
- TYPE\_INTEGER
- TYPE\_BOOLEAN
- TYPE\_FLOAT

Constants by sort

- SORT\_DESC
- SORT\_ASC

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

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

6

Last Release

936d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/63a84b9b680bd78e5ce9e59937330e49e20c065b6d147ba2b0f246087a66aa7f?d=identicon)[reptily](/maintainers/reptily)

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/reptily-array-list/health.svg)

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

PHPackages © 2026

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