PHPackages                             smoren/array-view - 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. [Templating &amp; Views](/categories/templating)
4. /
5. smoren/array-view

ActiveLibrary[Templating &amp; Views](/categories/templating)

smoren/array-view
=================

Create array views for easy data manipulation, select elements using Python-like slice notation, enable efficient selection of elements using index lists and boolean masks.

v1.0.0(2y ago)1291MITPHPPHP &gt;=7.4

Since Mar 10Pushed 1y ago1 watchersCompare

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

READMEChangelog (10)Dependencies (6)Versions (19)Used By (0)

Array View PHP
==============

[](#array-view-php)

[![Packagist PHP Version Support](https://camo.githubusercontent.com/bb9a0279c7f4d1237b416f84122efb470b52054a345dcefe4f76ec700539f98d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f736d6f72656e2f61727261792d76696577)](https://camo.githubusercontent.com/bb9a0279c7f4d1237b416f84122efb470b52054a345dcefe4f76ec700539f98d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f736d6f72656e2f61727261792d76696577)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/1b36fa49271a638488de98a9946dc5bf59dfa292f6cba2689871fde2983fcc4c/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f536d6f72656e2f61727261792d766965772d7068702f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Smoren/array-view-php/?branch=master)[![Coverage Status](https://camo.githubusercontent.com/f70badbee30e4501a54e53f882717abb1e97ac498fe5d086875f437a7173197f/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f536d6f72656e2f61727261792d766965772d7068702f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/Smoren/array-view-php?branch=master)[![Build and test](https://github.com/Smoren/array-view-php/actions/workflows/test.yml/badge.svg)](https://github.com/Smoren/array-view-php/actions/workflows/test.yml/badge.svg)[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)

[![Array View Logo](docs/images/logo.png)](docs/images/logo.png)

**Array View** is a PHP library that provides powerful abstractions and utilities for working with lists of data. Create views of arrays, slice and index using Python-like notation, transform and select your data using chained and fluent operations.

Features
--------

[](#features)

- Array views as an abstraction over an array
- Forward and backward array indexing
- Selecting and slicing using [Python-like slice notation](https://www.geeksforgeeks.org/python-list-slicing/)
- Filtering, mapping, matching and masking
- Chaining operations via pipes and fluent interfaces

How to install to your project
------------------------------

[](#how-to-install-to-your-project)

```
composer require smoren/array-view
```

Usage
-----

[](#usage)

### Indexing

[](#indexing)

Index into an array forward or backwards using positive or negative indexes.

Data1234567*Positive Index*0*1**2**3**4**5**6**Negative Index**-7**-6**-5**-4**-3**-2**-1*```
use Smoren\ArrayView\Views\ArrayView;

$view = ArrayView::toView([1, 2, 3, 4, 5, 6, 7]);

$view[0];  // 1
$view[1];  // 2
$view[-1]; // 7
$view[-2]; // 6
```

### Slices

[](#slices)

Use [Python-like slice notation](https://www.geeksforgeeks.org/python-list-slicing/) to select a range of elements: `[start, stop, step]`.

```
use Smoren\ArrayView\Views\ArrayView;

$originalArray = [1, 2, 3, 4, 5, 6, 7, 8, 9];
$view = ArrayView::toView($originalArray);

$view['1:6'];   // [2, 3, 4, 5, 6]
$view['1:7:2']; // [2, 4, 6]
$view[':3'];    // [1, 2, 3]
$view['::-1'];  // [9, 8, 7, 6, 5, 4, 3, 2, 1]
```

Insert into parts of the array.

```
$view['1:7:2'] = [22, 44, 66];
print_r($originalArray); // [1, 22, 3, 44, 5, 66, 7, 8, 9]
```

### Subviews

[](#subviews)

Create subviews of the original view using masks, indexes, and slices.

```
use Smoren\ArrayView\Selectors\IndexListSelector;
use Smoren\ArrayView\Selectors\MaskSelector;
use Smoren\ArrayView\Selectors\SliceSelector;
use Smoren\ArrayView\Views\ArrayView;

$originalArray = [1, 2, 3, 4, 5];
$view = ArrayView::toView($originalArray);

// Object-oriented style
$view->subview(new MaskSelector([true, false, true, false, true]))->toArray(); // [1, 3, 5]
$view->subview(new IndexListSelector([1, 2, 4]))->toArray();                   // [2, 3, 5]
$view->subview(new SliceSelector('::-1'))->toArray();                          // [5, 4, 3, 2, 1]

// Scripting style
$view->subview([true, false, true, false, true])->toArray(); // [1, 3, 5]
$view->subview([1, 2, 4])->toArray();                        // [2, 3, 5]
$view->subview('::-1')->toArray();                           // [5, 4, 3, 2, 1]

$view->subview(new MaskSelector([true, false, true, false, true]))->apply(fn ($x) => x * 10);
print_r($originalArray); // [10, 2, 30, 4, 50]
```

### Subarray Multi-indexing

[](#subarray-multi-indexing)

Directly select multiple elements using an array-index multi-selection.

```
use Smoren\ArrayView\Selectors\IndexListSelector;
use Smoren\ArrayView\Selectors\MaskSelector;
use Smoren\ArrayView\Selectors\SliceSelector;
use Smoren\ArrayView\Views\ArrayView;

$originalArray = [1, 2, 3, 4, 5];
$view = ArrayView::toView($originalArray);

// Object-oriented style
$view[new MaskSelector([true, false, true, false, true])]; // [1, 3, 5]
$view[new IndexListSelector([1, 2, 4])];                   // [2, 3, 5]
$view[new SliceSelector('::-1')];                          // [5, 4, 3, 2, 1]

// Scripting style
$view[[true, false, true, false, true]]; // [1, 3, 5]
$view[[1, 2, 4]];                        // [2, 3, 5]
$view['::-1'];                           // [5, 4, 3, 2, 1]

$view[new MaskSelector([true, false, true, false, true])] = [10, 30, 50];
print_r($originalArray); // [10, 2, 30, 4, 50]
```

### Combining Subviews

[](#combining-subviews)

Combine and chain subviews one after another in a fluent interface to perform multiple selection operations.

```
use Smoren\ArrayView\Selectors\IndexListSelector;
use Smoren\ArrayView\Selectors\MaskSelector;
use Smoren\ArrayView\Selectors\SliceSelector;
use Smoren\ArrayView\Views\ArrayView;

$originalArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

// Fluent object-oriented style
$subview = ArrayView::toView($originalArray)
    ->subview(new SliceSelector('::2'))                          // [1, 3, 5, 7, 9]
    ->subview(new MaskSelector([true, false, true, true, true])) // [1, 5, 7, 9]
    ->subview(new IndexListSelector([0, 1, 2]))                  // [1, 5, 7]
    ->subview(new SliceSelector('1:'));                          // [5, 7]

$subview[':'] = [55, 77];
print_r($originalArray); // [1, 2, 3, 4, 55, 6, 77, 8, 9, 10]

// Fluent scripting style
$originalArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
$subview = ArrayView::toView($originalArray)
    ->subview('::2')                           // [1, 3, 5, 7, 9]
    ->subview([true, false, true, true, true]) // [1, 5, 7, 9]
    ->subview([0, 1, 2])                       // [1, 5, 7]
    ->subview('1:');                           // [5, 7]

$subview[':'] = [55, 77];
print_r($originalArray); // [1, 2, 3, 4, 55, 6, 77, 8, 9, 10]
```

### Selectors Pipe

[](#selectors-pipe)

Create pipelines of selections that can be saved and applied again and again to new array views.

```
use Smoren\ArrayView\Selectors\IndexListSelector;
use Smoren\ArrayView\Selectors\MaskSelector;
use Smoren\ArrayView\Selectors\SliceSelector;
use Smoren\ArrayView\Views\ArrayView;

$originalArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
$selector = new PipeSelector([
    new SliceSelector('::2'),
    new MaskSelector([true, false, true, true, true]),
    new IndexListSelector([0, 1, 2]),
    new SliceSelector('1:'),
]);

$view = ArrayView::toView($originalArray);
$subview = $view->subview($selector);
print_r($subview[':']); // [5, 7]

$subview[':'] = [55, 77];
print_r($originalArray); // [1, 2, 3, 4, 55, 6, 77, 8, 9, 10]
```

Documentation
-------------

[](#documentation)

For detailed documentation and usage examples, please refer to the [API documentation](https://smoren.github.io/array-view-php/packages/Application.html).

Unit testing
------------

[](#unit-testing)

```
composer install
composer test-init
composer test

```

Contributing
------------

[](#contributing)

Contributions are welcome! Feel free to open an issue or submit a pull request on the [GitHub repository](https://github.com/Smoren/array-view-php).

Standards
---------

[](#standards)

ArrayView conforms to the following standards:

- PSR-1 — [Basic coding standard](https://www.php-fig.org/psr/psr-1/)
- PSR-4 — [Autoloader](https://www.php-fig.org/psr/psr-4/)
- PSR-12 — [Extended coding style guide](https://www.php-fig.org/psr/psr-12/)

License
-------

[](#license)

ArrayView PHP is licensed under the MIT License.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance31

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 94.1% 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

17

Last Release

790d ago

Major Versions

v0.6.0 → v1.0.02024-03-20

### Community

Maintainers

![](https://www.gravatar.com/avatar/fdc9e8df44cbbc0fc88885a4f1daa2cad755266e73eb0bac15efaf0d47ecbae2?d=identicon)[smoren](/maintainers/smoren)

---

Top Contributors

[![Smoren](https://avatars.githubusercontent.com/u/7403235?v=4)](https://github.com/Smoren "Smoren (112 commits)")[![markrogoyski](https://avatars.githubusercontent.com/u/10004372?v=4)](https://github.com/markrogoyski "markrogoyski (7 commits)")

---

Tags

arrayarray-viewarray-viewergood-first-issuemaskpython-likeselectorsliceviewarraycollectioncollectionsviewselectorindexingrangeslicepython-likedata-viewslicingarray-viewarray-indexnegative-indexesnegativearray-viewer

###  Code Quality

TestsCodeception

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/smoren-array-view/health.svg)

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

###  Alternatives

[eftec/bladeone

The standalone version Blade Template Engine from Laravel in a single php file

8208.4M87](/packages/eftec-bladeone)[laracasts/presenter

Simple view presenters

8643.4M46](/packages/laracasts-presenter)[laminas/laminas-view

Fast and type safe HTML templating library with a flexible plugin system supporting multistep template composition

7526.3M230](/packages/laminas-laminas-view)[jasny/twig-extensions

A set of useful Twig filters

10710.2M8](/packages/jasny-twig-extensions)[vistik/typed-collections

A simple way to create typed collections in PHP - build on Illuminate\\Support\\Collection

1128.2k5](/packages/vistik-typed-collections)[rotexsoft/versatile-collections

A collection package that can be extended to implement things such as a Dependency Injection Container, RecordSet objects for housing database records, a bag of http cookies, or technically any collection of items that can be looped over and whose items can each be accessed using array-access syntax or object property syntax.

186.0k1](/packages/rotexsoft-versatile-collections)

PHPackages © 2026

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