PHPackages                             hoffmann-oss/arrays - 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. hoffmann-oss/arrays

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

hoffmann-oss/arrays
===================

PHP 7 array functions

1.0.0(9y ago)1356MITPHPPHP &gt;=7.0CI failing

Since Nov 19Pushed 6y ago1 watchersCompare

[ Source](https://github.com/hoffmann-oss/arrays-php)[ Packagist](https://packagist.org/packages/hoffmann-oss/arrays)[ Docs](https://github.com/hoffmann-oss/arrays-php)[ RSS](/packages/hoffmann-oss-arrays/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (2)Used By (0)

`hoffmann-oss/arrays-php`
=========================

[](#hoffmann-ossarrays-php)

A PHP 7 array manipulation library.

Installation with Composer
--------------------------

[](#installation-with-composer)

This package is available on [packagist](https://packagist.org/packages/hoffmann-oss/arrays), so you can use [Composer](https://getcomposer.org) to install it. Run the following command in your shell:

```
composer require hoffmann-oss/arrays

```

The `Arrays` class
==================

[](#the-arrays-class)

create()
--------

[](#create)

```
public static function &create(int $size, $item = null): array

```

### Example:

[](#example)

```
$array = Arrays::create(5, 1000);
```

the resulting array:

```
[1000, 1000, 1000, 1000, 1000]
```

fill()
------

[](#fill)

```
public static function fill(
    array &$array,
    $item = null,
    int $start = 0,
    int $stop = null
)

```

### Example:

[](#example-1)

```
$array1 = $array2 = [1, 2, 3, 4, 5, 6, 7, 8];
Arrays::fill($array1, 1000);
Arrays::fill($array2, 1000, 2, 6);
```

the resulting arrays:

```
[1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000]
[1, 2, 1000, 1000, 1000, 1000, 7, 8]
```

replace()
---------

[](#replace)

```
public static function replace(
    array &$array,
    array $source,
    int $position = 0,
    int $start = 0,
    int $stop = null
)

```

### Example:

[](#example-2)

```
$array1 = $array2 = [1, 2, 3, 4, 5, 6, 7, 8];
$source = [1001, 1002, 1003, 1004, 1005];
Arrays::replace($array1, $source, 4);
Arrays::replace($array2, $source, 4, 2, 6);
```

the resulting arrays:

```
[1, 2, 3, 4, 1001, 1002, 1003, 1004]
[1, 2, 3, 4, 1001, 1002, 7, 8]
```

reverse()
---------

[](#reverse)

```
public static function reverse(
    array &$array,
    int $start = 0,
    int $stop = null
)

```

### Example:

[](#example-3)

```
$array1 = $array2 = [1, 2, 3, 4, 5, 6, 7, 8];
Arrays::reverse($array1);
Arrays::reverse($array2, 2, 6);
```

the resulting arrays:

```
[8, 7, 6, 5, 4, 3, 2, 1]
[1, 2, 6, 5, 4, 3, 7, 8]
```

rotate()
--------

[](#rotate)

```
public static function rotate(
    array &$array,
    int $distance,
    int $start = 0,
    int $stop = null
)

```

### Example:

[](#example-4)

```
$array1 = $array2 = [1, 2, 3, 4, 5, 6, 7, 8];
Arrays::rotate($array1, -2);
Arrays::rotate($array2, 2, 2, 6);
```

the resulting arrays:

```
[7, 8, 1, 2, 3, 4, 5, 6]
[1, 2, 5, 6, 3, 4, 7, 8]
```

shuffle()
---------

[](#shuffle)

```
public static function shuffle(
    array &$array,
    int $start = 0,
    int $stop = null
)

```

### Example:

[](#example-5)

```
$array1 = $array2 = [1, 2, 3, 4, 5, 6, 7, 8];
Arrays::shuffle($array1);
Arrays::shuffle($array2, 2, 6);
```

the resulting arrays:

```
[4, 6, 1, 2, 8, 7, 5, 3]
[1, 2, 3, 5, 6, 4, 7, 8]
```

swap()
------

[](#swap)

```
public static function swap(
    array &$array,
    int $index1,
    int $index2
)

```

### Example:

[](#example-6)

```
$array = [1, 2, 3, 4];
Arrays::swap($array, 0, 1);
Arrays::swap($array, 1, 2);
Arrays::swap($array, 2, 3);
```

the resulting array:

```
[2, 3, 4, 1]
```

pick()
------

[](#pick)

```
public static function pick(
    array $array,
    int $start = 0,
    int $stop = null
)

```

### Example:

[](#example-7)

```
$source = [1, 2, 3, 4, 5, 6, 7, 8];
$array1 = $array2 = [];
for ($i = 0; $i < 10; $i++) {
    $array1[] = Arrays::pick($source);
    $array2[] = Arrays::pick($source, 2, 6);
}
```

the resulting arrays:

```
[8, 2, 1, 3, 3, 7, 3, 1, 7, 6]
[5, 3, 4, 6, 5, 4, 6, 3, 3, 6]
```

The `Arrays2d` class
====================

[](#the-arrays2d-class)

The functions of this class assumes that the parameter `$array` is a rectangular array (y) of arrays (x).

create()
--------

[](#create-1)

```
public static function &create(int $width, int $height, $item = null): array

```

### Example:

[](#example-8)

```
$array = Arrays2d::create(3, 3, 1000);
```

the resulting array:

```
[
    [1000, 1000, 1000],
    [1000, 1000, 1000],
    [1000, 1000, 1000]
]
```

fill()
------

[](#fill-1)

```
public static function fill(
    array &$array,
    $item = null,
    int $startX = 0,
    int $startY = 0,
    int $stopX = null,
    int $stopY = null
)

```

### Example:

[](#example-9)

```
$array1 = $array2 = [
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9]
];
Arrays2d::fill($array1, 1000);
Arrays2d::fill($array2, 1000, 1, 0, 3, 2);
```

the resulting arrays:

```
[
    [1000, 1000, 1000],
    [1000, 1000, 1000],
    [1000, 1000, 1000]
]
[
    [1, 1000, 1000],
    [4, 1000, 1000],
    [7, 8, 9]
]
```

replace()
---------

[](#replace-1)

```
public static function replace(
    array &$array,
    array $source,
    int $x = 0,
    int $y = 0,
    int $startX = 0,
    int $startY = 0,
    int $stopX = null,
    int $stopY = null
)

```

### Example:

[](#example-10)

```
$array1 = $array2 = [
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9]
];
$source = [
    [1001, 1002, 1003],
    [1004, 1005, 1006],
    [1007, 1008, 1009]
];
Arrays2d::replace($array1, $source, 0, 0);
Arrays2d::replace($array2, $source, 0, 0, 1, 0, 3, 2);
```

the resulting arrays:

```
[
    [1001, 1002, 1003],
    [1004, 1005, 1006],
    [1007, 1008, 1009]
]
[
    [1, 1002, 1003],
    [4, 1005, 1006],
    [7, 8, 9]
]
```

reverseX()
----------

[](#reversex)

```
public static function reverseX(
    array &$array,
    int $startX = 0,
    int $startY = 0,
    int $stopX = null,
    int $stopY = null
)

```

### Example:

[](#example-11)

```
$array1 = $array2 = [
    [1, 2, 3, 4],
    [5, 6, 7, 8],
    [9, 10, 11, 12]
];
Arrays2d::reverseX($array1);
Arrays2d::reverseX($array2, 1, 0, 4, 2);
```

the resulting arrays:

```
[
    [4, 3, 2, 1],
    [8, 7, 6, 5],
    [12, 11, 10, 9]
]
[
    [1, 4, 3, 2],
    [5, 8, 7, 6],
    [9, 10, 11, 12]
]
```

reverseY()
----------

[](#reversey)

```
public static function reverseY(
    array &$array,
    int $startX = 0,
    int $startY = 0,
    int $stopX = null,
    int $stopY = null
)

```

### Example:

[](#example-12)

```
$array1 = $array2 = [
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9],
    [10, 11, 12]
];
Arrays2d::reverseY($array1);
Arrays2d::reverseY($array2, 1, 0, 3, 3);
```

the resulting arrays:

```
[
    [10, 11, 12],
    [7, 8, 9],
    [4, 5, 6],
    [1, 2, 3]
]
[
    [1, 8, 9],
    [4, 5, 6],
    [7, 2, 3],
    [10, 11, 12]
]
```

rotateX()
---------

[](#rotatex)

```
public static function rotateX(
    array &$array,
    int $distance,
    int $startX = 0,
    int $startY = 0,
    int $stopX = null,
    int $stopY = null
)

```

Array columns rotate left if distance is greater than 0.

### Example:

[](#example-13)

```
$array1 = $array2 = [
    [1, 2, 3, 4],
    [5, 6, 7, 8],
    [9, 10, 11, 12]
];
Arrays2d::rotateX($array1, 1);
Arrays2d::rotateX($array2, -1, 1, 0, 4, 2);
```

the resulting arrays:

```
[
    [2, 3, 4, 1],
    [6, 7, 8, 5],
    [10, 11, 12, 9]
]
[
    [1, 4, 2, 3],
    [5, 8, 6, 7],
    [9, 10, 11, 12]
]
```

rotateY()
---------

[](#rotatey)

```
public static function rotateY(
    array &$array,
    int $distance,
    int $startX = 0,
    int $startY = 0,
    int $stopX = null,
    int $stopY = null
)

```

Array rows rotate up if distance is greater than 0.

### Example:

[](#example-14)

```
$array1 = $array2 = [
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9],
    [10, 11, 12]
];
Arrays2d::rotateY($array1, 1);
Arrays2d::rotateY($array2, -1, 1, 0, 3, 3);
```

the resulting arrays:

```
[
    [4, 5, 6],
    [7, 8, 9],
    [10, 11, 12],
    [1, 2, 3]
]
[
    [1, 8, 9],
    [4, 2, 3],
    [7, 5, 6],
    [10, 11, 12]
]
```

shuffle()
---------

[](#shuffle-1)

```
public static function shuffle(
    array &$array,
    int $startX = 0,
    int $startY = 0,
    int $stopX = null,
    int $stopY = null
)

```

### Example:

[](#example-15)

```
$array1 = $array2 = [[1, 2, 3], [4, 5, 6], [7, 8, 9]];
Arrays2d::shuffle($array1);
Arrays2d::shuffle($array2, 1, 0, 3, 2);
```

the resulting arrays:

```
[
    [5, 2, 9],
    [3, 1, 4],
    [7, 8, 6]
]
[
    [1, 5, 3],
    [4, 6, 2],
    [7, 8, 9]
]
```

shuffleX()
----------

[](#shufflex)

```
public static function shuffleX(
    array &$array,
    int $startX = 0,
    int $startY = 0,
    int $stopX = null,
    int $stopY = null
)

```

### Example:

[](#example-16)

```
$array1 = $array2 = [
    [1, 2, 3, 4, 5],
    [6, 7, 8, 9, 10],
    [11, 12, 13, 14, 15]
];
Arrays2d::shuffleX($array1);
Arrays2d::shuffleX($array2, 1, 0, 5, 2);
```

the resulting arrays:

```
[
    [3, 5, 1, 2, 4],
    [8, 10, 6, 7, 9],
    [13, 15, 11, 12, 14]
]
[
    [1, 5, 4, 2, 3],
    [6, 10, 9, 7, 8],
    [11, 12, 13, 14, 15]
]
```

shuffleY()
----------

[](#shuffley)

```
public static function shuffleY(
    array &$array,
    int $startX = 0,
    int $startY = 0,
    int $stopX = null,
    int $stopY = null
)

```

### Example:

[](#example-17)

```
$array1 = $array2 = [
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9],
    [10, 11, 12],
    [13, 14, 15]
];
Arrays2d::shuffleY($array1);
Arrays2d::shuffleY($array2, 1, 0, 3, 4);
```

the resulting arrays:

```
[
    [4, 5, 6],
    [1, 2, 3],
    [10, 11, 12],
    [13, 14, 15],
    [7, 8, 9]
]
[
    [1, 11, 12],
    [4, 5, 6],
    [7, 8, 9],
    [10, 2, 3],
    [13, 14, 15]
]
```

swap()
------

[](#swap-1)

```
public static function swap(
    array &$array,
    int $x1,
    int $y1,
    int $x2,
    int $y2
)

```

### Example:

[](#example-18)

```
$array = [
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9]
];
Arrays2d::swap($array, 0, 1, 2, 0);
Arrays2d::swap($array, 0, 2, 2, 1);
```

the resulting array:

```
[
    [1, 2, 4],
    [3, 5, 7],
    [6, 8, 9]
]
```

swapX()
-------

[](#swapx)

```
public static function swapX(
    array &$array,
    int $x1,
    int $x2,
    int $startY = 0,
    int $stopY = null
)

```

### Example:

[](#example-19)

```
$array1 = $array2 = [
    [1, 2, 3, 4],
    [5, 6, 7, 8],
    [9, 10, 11, 12]
];
Arrays2d::swapX($array1, 2, 3);
Arrays2d::swapX($array2, 2, 3, 0, 2);
```

the resulting arrays:

```
[
    [1, 2, 4, 3],
    [5, 6, 8, 7],
    [9, 10, 12, 11]
]
[
    [1, 2, 4, 3],
    [5, 6, 8, 7],
    [9, 10, 11, 12]
]
```

swapY()
-------

[](#swapy)

```
public static function swapY(
    array &$array,
    int $y1,
    int $y2,
    int $startX = 0,
    int $stopX = null
)

```

### Example:

[](#example-20)

```
$array1 = $array2 = [
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9],
    [10, 11, 12]
];
Arrays2d::swapY($array1, 2, 3);
Arrays2d::swapY($array2, 2, 3, 0, 2);
```

the resulting arrays:

```
[
    [1, 2, 3],
    [4, 5, 6],
    [10, 11, 12],
    [7, 8, 9]
]
[
    [1, 2, 3],
    [4, 5, 6],
    [10, 11, 9],
    [7, 8, 12]
]
```

pick()
------

[](#pick-1)

```
public static function pick(
    array $array,
    int $startX = 0,
    int $startY = 0,
    int $stopX = null,
    int $stopY = null
)

```

### Example:

[](#example-21)

```
$source = [
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9]
];
$array1 = $array2 = [];
for ($i = 0; $i < 10; $i++) {
    $array1[] = Arrays2d::pick($source);
    $array2[] = Arrays2d::pick($source, 0, 0, 2, 2);
}
```

the resulting arrays:

```
[5, 7, 8, 9, 2, 2, 6, 7, 5, 2]
[1, 2, 1, 4, 4, 4, 1, 2, 1, 2]
```

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

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

Unknown

Total

1

Last Release

3509d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/883f60c1f1597b050fd507ef6de0fd047050f85dc4af0dbb936cd6549244a36e?d=identicon)[hoffmann-oss](/maintainers/hoffmann-oss)

---

Top Contributors

[![hoffmann-oss](https://avatars.githubusercontent.com/u/14338009?v=4)](https://github.com/hoffmann-oss "hoffmann-oss (7 commits)")

---

Tags

2darraysphp7rotateshuffleutilityarrays

### Embed Badge

![Health badge](/badges/hoffmann-oss-arrays/health.svg)

```
[![Health](https://phpackages.com/badges/hoffmann-oss-arrays/health.svg)](https://phpackages.com/packages/hoffmann-oss-arrays)
```

###  Alternatives

[nette/utils

🛠 Nette Utils: lightweight utilities for string &amp; array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.

2.1k417.9M1.7k](/packages/nette-utils)[danielstjules/stringy

A string manipulation library with multibyte support

2.4k26.2M192](/packages/danielstjules-stringy)[voku/arrayy

Array manipulation library for PHP, called Arrayy!

4885.6M18](/packages/voku-arrayy)[mage2tv/magento-cache-clean

This package has been migrated to mage-os/magento-cache-clean. Please switch over at your convenience.

5442.1M3](/packages/mage2tv-magento-cache-clean)[vaimo/composer-patches

Applies a patch from a local or remote file to any package that is part of a given composer project. Patches can be defined both on project and on package level. Optional support for patch versioning, sequencing, custom patch applier configuration and patch command for testing/troubleshooting added patches.

3014.5M22](/packages/vaimo-composer-patches)[phpcsstandards/phpcsutils

A suite of utility functions for use with PHP\_CodeSniffer

6337.7M90](/packages/phpcsstandards-phpcsutils)

PHPackages © 2026

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