PHPackages                             petrobolos/fixed-array-functions - 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. petrobolos/fixed-array-functions

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

petrobolos/fixed-array-functions
================================

Laravel helper methods for working with high performance SPL fixed arrays.

v3.1.0(3mo ago)066↓93.3%MITPHPPHP ^8.4CI passing

Since May 6Pushed 2mo agoCompare

[ Source](https://github.com/oliverearl/fixed-array-functions)[ Packagist](https://packagist.org/packages/petrobolos/fixed-array-functions)[ Docs](https://github.com/oliverearl/fixed-array-functions)[ GitHub Sponsors](https://github.com/oliverearl)[ Fund](https://ko-fi.com/oliverearl)[ RSS](/packages/petrobolos-fixed-array-functions/feed)WikiDiscussions main Synced today

READMEChangelog (10)Dependencies (32)Versions (17)Used By (0)

Fixed Array Functions
=====================

[](#fixed-array-functions)

[![Latest Version on Packagist](https://camo.githubusercontent.com/b51e471a6f35abda0571facf2fef1092cf9fa1234a0c8c9e879ade852d04fde9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f706574726f626f6c6f732f66697865642d61727261792d66756e6374696f6e732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/petrobolos/fixed-array-functions)[![GitHub issues](https://camo.githubusercontent.com/663d39dfcb28367a6bc7da448eb70f5fdde72143cd03873ab7a38f9f4d6024a2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f706574726f626f6c6f732f66697865642d61727261792d66756e6374696f6e73)](https://github.com/petrobolos/fixed-array-functions/issues)[![GitHub Tests Action Status](https://camo.githubusercontent.com/3382772359514eec386d7a7cdbc1423bfca05f87b593f1082184f67b94f6e21e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f706574726f626f6c6f732f66697865642d61727261792d66756e6374696f6e732f72756e2d74657374732e796d6c3f6c6162656c3d74657374266272616e63683d6d61696e)](https://github.com/petrobolos/fixed-array-functions/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/af38aac3315ca3e94c10ebe889d774e440a13462a34b70fd17d817570a13ed3e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f706574726f626f6c6f732f66697865642d61727261792d66756e6374696f6e732f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6c6162656c3d6c696e74266272616e63683d6d61696e)](https://github.com/petrobolos/fixed-array-functions/actions?query=workflow%3A%22Check+%26+fix+styling%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/f590bf5338277b3047021c564c4bcb36c098b8b9073b2e0a51a5c6a58f7f3504/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f706574726f626f6c6f732f66697865642d61727261792d66756e6374696f6e732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/petrobolos/fixed-array-functions)[![GitHub](https://camo.githubusercontent.com/24742fe0b21360bba7326406b3301b5ac4681490b976d47a75408ec16ee3e704/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f706574726f626f6c6f732f66697865642d61727261792d66756e6374696f6e73)](https://www.github.com/petrobolos/fixed-array-functions)

SplFixedArrays are an implementation of a traditional, bounded array in the PHP standard library.

While they require manual resizing, they're significantly faster than regular arrays or collections when working with large sets of data.

Requirements
------------

[](#requirements)

Currently, requires PHP 8.4 or above, and Laravel 12+.

Installation
------------

[](#installation)

You can install the package via Composer:

```
composer require petrobolos/fixed-array-functions
```

Quick Start
-----------

[](#quick-start)

### Fluent interface

[](#fluent-interface)

FixedArray is best used with its fluent interface. If you're familiar with Illuminate collections, you'll feel right at home. Provide it an SplFixedArray to get started, or a standard array or collection that will be automatically converted.

```
use Petrobolos\FixedArray\FixedArrayable;

// Create using various methods
$array = new FixedArrayable([1, 2, 3]);
$array = fixedArray([1, 2, 3]);  // Helper function
$array = FixedArrayable::fromCollection(collect([1, 2, 3]));

// Chain methods just like Laravel Collections
$result = fixedArray([1, 2, 3, 4, 5, 6])
    ->filter(fn ($value) => $value % 2 === 0)
    ->map(fn ($value) => $value * 2)
    ->sum();  // Returns 24 (2*2 + 4*2 + 6*2)
```

### Static methods

[](#static-methods)

You aren't forced to use the fluent interface and can access methods directly by calling them. This is useful if you only need to do one or two operations on a fixed array.

```
use Petrobolos\FixedArray\FixedArray;

$arr = FixedArray::fromArray([1, 2, 3, 4, 5]);

// Aggregate functions
$sum = FixedArray::sum($arr);           // 15
$avg = FixedArray::avg($arr);           // 3
$min = FixedArray::min($arr);           // 1
$max = FixedArray::max($arr);           // 5

// Higher-order functions
$doubled = FixedArray::map($arr, fn($v) => $v * 2);
$evens = FixedArray::filter($arr, fn($v) => $v % 2 === 0);

// Conditional operations
$result = FixedArray::when(
    $arr,
    fn($a) => FixedArray::count($a) > 3,
    fn($a) => FixedArray::push($a, 6)
);
```

Real-World Examples
-------------------

[](#real-world-examples)

### Processing Large Datasets

[](#processing-large-datasets)

```
// Efficiently process 100,000 records
$data = FixedArray::create(100000);

for ($i = 0; $i < 100000; $i++) {
    FixedArray::offsetSet($data, $i, fetchRecordFromDatabase($i));
}

$processed = fixedArray($data)
    ->filter(fn($record) => $record->isActive)
    ->map(fn($record) => $record->transform())
    ->toCollection(); // Convert back to Collection for further Laravel operations
```

### Data Aggregation

[](#data-aggregation)

```
$orders = fixedArray($orderArray)
    ->pluck('total')
    ->sum();

$averageAge = fixedArray($users)
    ->avg('age');

$oldestUser = fixedArray($users)
    ->max('created_at');
```

### Conditional Transformations

[](#conditional-transformations)

```
$processed = fixedArray($items)
    ->when(
        $shouldFilter,
        fn($arr) => $arr->filter(fn($item) => $item->isValid())
    )
    ->unless(
        $skipSorting,
        fn($arr) => $arr->sort()
    )
    ->tap(fn($arr) => logger()->info('Processed items', ['count' => $arr->count()]))
    ->toArray();
```

### Partitioning Data

[](#partitioning-data)

```
[$valid, $invalid] = fixedArray($records)
    ->partition(fn($record) => $record->validate())
    ->toArray();

// $valid contains all validated records
// $invalid contains all failed records
```

Performance Benefits
--------------------

[](#performance-benefits)

`SplFixedArray` offers significant performance advantages over standard PHP arrays for large datasets:

- **Memory Efficiency**: Uses approximately 50% less memory than standard arrays
- **Faster Access**: Direct memory access without hash table overhead
- **Predictable Performance**: O(1) access time for all operations

**When to use SplFixedArray:**

- Working with large datasets (10,000+ elements)
- Memory-constrained environments
- Performance-critical array operations
- Known array size at creation time

**When to stick with regular arrays/Collections:**

- Small datasets (&lt; 1,000 elements)
- Dynamic sizing with frequent additions/removals
- Need associative keys or complex key types

Full list of available methods
------------------------------

[](#full-list-of-available-methods)

MethodDescriptionaddAlias for push.addFromAdd an array or collection of items to a fixed array.allAlias for every.avgCalculate the average of numeric values.averageAlias for avg.chunkSplit a fixed array into chunks of a given size.chunkWhileSplit a fixed array into chunks while a callback returns true.containsCheck whether an item exists in a fixed array.countReturn the number of elements.createCreate a new fixed array of a given size.dsfargegDSFARGEGeachApply a callback to each item without modifying the original array.everyDetermine if all items pass a given test.fillFill the array with a single value.filterFilter the array using a callback (passes key to callback).findReturn the first element matching a callback.findKeyReturn the key of the first element matching a callback.findIndexAlias for findKey.firstReturn the first element of the array.flattenFlatten nested arrays, collections, and fixed arrays.fluentCreates a new fluent interface for chaining methods.fromArrayCreate a fixed array from a standard array.fromCollectionCreate a fixed array from an Illuminate collection.getSizeReturn the number of elements in the array.implodeAlias for join.isEmptyCheck if the array is empty.isFixedArrayCheck whether a value is a fixed array.isNotEmptyCheck if the array is not empty.joinJoin array elements with a string.keysGet all keys (indices) from the array.lastReturn the last element of the array.mapApply a callback to each item and return a new array.maxFind the maximum value.mergeMerge multiple arrays, fixed arrays, or collections.minFind the minimum value.nullifyReplace all elements with null.offsetExistsCheck if an index exists in the array.offsetGetGet the value at a specific index.offsetNullSet a specific index to null.offsetSetSet a value at a specific index.partitionSplit array into two groups based on a callback.pipePass the array through a callback and return the result.pluckExtract values from a specific property or key.popRemove and return the last element.pushAdd a value to the first available space.randomReturn a random element from the array.reduceReduce the array to a single value using a callback.rejectFilter out items that pass the test (opposite of filter).resizeAlias for setSize.reverseReverse the order of elements.secondReturn the second element.setSizeResize the array to a given size.shiftRemove and return the first element.shuffleShuffle the array in a secure manner.sliceReturn a subset of the array.someDetermine if at least one item passes a given test.sortSort the array optionally using a callback.sumSum all numeric values in the array.tapPass the array to a callback and return the array.toArrayConvert the fixed array into a standard PHP array.toCollectionConvert the fixed array into an Illuminate collection.uniqueRemove duplicate values from the array.unshiftPrepend one or more values to the array.unlessApply callback if the condition is false.valuesGet all values from the array (reindexed).whenApply callback if the condition is true.Testing
-------

[](#testing)

Tests are run using Pest. You can run the suite like so:

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

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

[](#contributing)

We welcome pull requests, especially those improving the package's optimisation and speed, and new features to bring it into parity with Collection.

Please ensure any functionality submitted has adequate test coverage and documentation (at least in English.)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

47

—

FairBetter than 93% of packages

Maintenance83

Actively maintained with recent releases

Popularity8

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 79.7% 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 ~108 days

Recently: every ~94 days

Total

14

Last Release

107d ago

Major Versions

v1.2.6 → v2.0.02024-12-14

v2.1.2 → v3.0.02025-12-09

PHP version history (3 changes)v1.0.0PHP ^8.0 || ^8.1

v2.0.0PHP ^8.3

v3.0.0PHP ^8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/10ca9d5f46f753e8297ae6cc53c018fa833f9e1bc7785c6397a45e7fbc17f033?d=identicon)[oliverearl](/maintainers/oliverearl)

---

Top Contributors

[![oliverearl](https://avatars.githubusercontent.com/u/14837181?v=4)](https://github.com/oliverearl "oliverearl (149 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (25 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (13 commits)")

---

Tags

laravelphpphp8spllaravelarraycollectionsplfixedarray

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/petrobolos-fixed-array-functions/health.svg)

```
[![Health](https://phpackages.com/badges/petrobolos-fixed-array-functions/health.svg)](https://phpackages.com/packages/petrobolos-fixed-array-functions)
```

###  Alternatives

[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k4.8M47](/packages/spatie-laravel-pdf)[codewithdennis/filament-select-tree

The multi-level select field enables you to make single selections from a predefined list of options that are organized into multiple levels or depths.

329530.5k29](/packages/codewithdennis-filament-select-tree)[worksome/exchange

Check Exchange Rates for any currency in Laravel.

124603.0k](/packages/worksome-exchange)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3914.6k](/packages/rawilk-profile-filament-plugin)[tarfin-labs/event-machine

Event-driven state machines for Laravel with event sourcing, type-safe context, and full audit trail.

199.4k](/packages/tarfin-labs-event-machine)[tapp/filament-form-builder

User facing form builder using Filament components

132.4k3](/packages/tapp-filament-form-builder)

PHPackages © 2026

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