{"id":33969996,"url":"https://github.com/oliverearl/fixed-array-functions","last_synced_at":"2026-04-06T02:01:30.737Z","repository":{"id":40476916,"uuid":"488005706","full_name":"oliverearl/fixed-array-functions","owner":"oliverearl","description":" Laravel helper methods for working with high performance SPL fixed arrays. (Requires PHP 8.4)","archived":false,"fork":false,"pushed_at":"2026-03-18T07:56:43.000Z","size":180,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-03-18T23:15:07.657Z","etag":null,"topics":["laravel","php","php8","spl"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/oliverearl.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":"AGENTS.md","dco":null,"cla":null},"funding":{"github":"oliverearl","ko_fi":"oliverearl"}},"created_at":"2022-05-02T22:14:06.000Z","updated_at":"2026-03-18T07:56:46.000Z","dependencies_parsed_at":"2024-12-14T15:17:59.567Z","dependency_job_id":"106e404c-8628-43eb-8d20-5212ef194e1e","html_url":"https://github.com/oliverearl/fixed-array-functions","commit_stats":null,"previous_names":["oliverearl/fixed-array-functions","petrobolos/fixed-array-functions"],"tags_count":16,"template":false,"template_full_name":"spatie/package-skeleton-laravel","purl":"pkg:github/oliverearl/fixed-array-functions","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oliverearl%2Ffixed-array-functions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oliverearl%2Ffixed-array-functions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oliverearl%2Ffixed-array-functions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oliverearl%2Ffixed-array-functions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oliverearl","download_url":"https://codeload.github.com/oliverearl/fixed-array-functions/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oliverearl%2Ffixed-array-functions/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31456664,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-05T21:22:52.476Z","status":"online","status_checked_at":"2026-04-06T02:00:07.287Z","response_time":112,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["laravel","php","php8","spl"],"created_at":"2025-12-13T00:05:08.071Z","updated_at":"2026-04-06T02:01:30.732Z","avatar_url":"https://github.com/oliverearl.png","language":"PHP","funding_links":["https://github.com/sponsors/oliverearl","https://ko-fi.com/oliverearl"],"categories":[],"sub_categories":[],"readme":"# Fixed Array Functions\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/petrobolos/fixed-array-functions.svg?style=flat-square)](https://packagist.org/packages/petrobolos/fixed-array-functions)\n[![GitHub issues](https://img.shields.io/github/issues/petrobolos/fixed-array-functions)](https://github.com/petrobolos/fixed-array-functions/issues)\n[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/petrobolos/fixed-array-functions/run-tests.yml?label=test\u0026branch=main)](https://github.com/petrobolos/fixed-array-functions/actions?query=workflow%3Arun-tests+branch%3Amain)\n[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/petrobolos/fixed-array-functions/fix-php-code-style-issues.yml?label=lint\u0026branch=main)](https://github.com/petrobolos/fixed-array-functions/actions?query=workflow%3A\"Check+%26+fix+styling\"+branch%3Amain)\n[![Total Downloads](https://img.shields.io/packagist/dt/petrobolos/fixed-array-functions.svg?style=flat-square)](https://packagist.org/packages/petrobolos/fixed-array-functions)\n[![GitHub](https://img.shields.io/github/license/petrobolos/fixed-array-functions)](https://www.github.com/petrobolos/fixed-array-functions)\n\nSplFixedArrays are an implementation of a traditional, bounded array in the PHP standard library.\n\nWhile they require manual resizing, they're significantly faster than regular arrays or collections when working with\nlarge sets of data.\n\n## Requirements\n\nCurrently, requires PHP 8.4 or above, and Laravel 12+.\n\n## Installation\n\nYou can install the package via Composer:\n\n```bash\ncomposer require petrobolos/fixed-array-functions\n```\n\n## Quick Start\n\n### Fluent interface\n\nFixedArray is best used with its fluent interface. If you're familiar with Illuminate collections, you'll feel right at\nhome. Provide it an SplFixedArray to get started, or a standard array or collection that will be automatically\nconverted.\n\n```php\nuse Petrobolos\\FixedArray\\FixedArrayable;\n\n// Create using various methods\n$array = new FixedArrayable([1, 2, 3]);\n$array = fixedArray([1, 2, 3]);  // Helper function\n$array = FixedArrayable::fromCollection(collect([1, 2, 3]));\n\n// Chain methods just like Laravel Collections\n$result = fixedArray([1, 2, 3, 4, 5, 6])\n    -\u003efilter(fn ($value) =\u003e $value % 2 === 0)\n    -\u003emap(fn ($value) =\u003e $value * 2)\n    -\u003esum();  // Returns 24 (2*2 + 4*2 + 6*2)\n```\n\n### Static methods\n\nYou aren't forced to use the fluent interface and can access methods directly by calling them. This is useful if you\nonly need to do one or two operations on a fixed array.\n\n```php\nuse Petrobolos\\FixedArray\\FixedArray;\n\n$arr = FixedArray::fromArray([1, 2, 3, 4, 5]);\n\n// Aggregate functions\n$sum = FixedArray::sum($arr);           // 15\n$avg = FixedArray::avg($arr);           // 3\n$min = FixedArray::min($arr);           // 1\n$max = FixedArray::max($arr);           // 5\n\n// Higher-order functions\n$doubled = FixedArray::map($arr, fn($v) =\u003e $v * 2);\n$evens = FixedArray::filter($arr, fn($v) =\u003e $v % 2 === 0);\n\n// Conditional operations\n$result = FixedArray::when(\n    $arr,\n    fn($a) =\u003e FixedArray::count($a) \u003e 3,\n    fn($a) =\u003e FixedArray::push($a, 6)\n);\n```\n\n## Real-World Examples\n\n### Processing Large Datasets\n\n```php\n// Efficiently process 100,000 records\n$data = FixedArray::create(100000);\n\nfor ($i = 0; $i \u003c 100000; $i++) {\n    FixedArray::offsetSet($data, $i, fetchRecordFromDatabase($i));\n}\n\n$processed = fixedArray($data)\n    -\u003efilter(fn($record) =\u003e $record-\u003eisActive)\n    -\u003emap(fn($record) =\u003e $record-\u003etransform())\n    -\u003etoCollection(); // Convert back to Collection for further Laravel operations\n```\n\n### Data Aggregation\n\n```php\n$orders = fixedArray($orderArray)\n    -\u003epluck('total')\n    -\u003esum();\n\n$averageAge = fixedArray($users)\n    -\u003eavg('age');\n\n$oldestUser = fixedArray($users)\n    -\u003emax('created_at');\n```\n\n### Conditional Transformations\n\n```php\n$processed = fixedArray($items)\n    -\u003ewhen(\n        $shouldFilter,\n        fn($arr) =\u003e $arr-\u003efilter(fn($item) =\u003e $item-\u003eisValid())\n    )\n    -\u003eunless(\n        $skipSorting,\n        fn($arr) =\u003e $arr-\u003esort()\n    )\n    -\u003etap(fn($arr) =\u003e logger()-\u003einfo('Processed items', ['count' =\u003e $arr-\u003ecount()]))\n    -\u003etoArray();\n```\n\n### Partitioning Data\n\n```php\n[$valid, $invalid] = fixedArray($records)\n    -\u003epartition(fn($record) =\u003e $record-\u003evalidate())\n    -\u003etoArray();\n\n// $valid contains all validated records\n// $invalid contains all failed records\n```\n\n## Performance Benefits\n\n`SplFixedArray` offers significant performance advantages over standard PHP arrays for large datasets:\n\n- **Memory Efficiency**: Uses approximately 50% less memory than standard arrays\n- **Faster Access**: Direct memory access without hash table overhead\n- **Predictable Performance**: O(1) access time for all operations\n\n**When to use SplFixedArray:**\n- Working with large datasets (10,000+ elements)\n- Memory-constrained environments\n- Performance-critical array operations\n- Known array size at creation time\n\n**When to stick with regular arrays/Collections:**\n- Small datasets (\u003c 1,000 elements)\n- Dynamic sizing with frequent additions/removals\n- Need associative keys or complex key types\n\n## Full list of available methods\n\n| Method         | Description                                                         |\n|:---------------|:--------------------------------------------------------------------|\n| add            | Alias for push.                                                     |\n| addFrom        | Add an array or collection of items to a fixed array.               |\n| all            | Alias for every.                                                    |\n| avg            | Calculate the average of numeric values.                            |\n| average        | Alias for avg.                                                      |\n| chunk          | Split a fixed array into chunks of a given size.                    |\n| chunkWhile     | Split a fixed array into chunks while a callback returns true.      |\n| contains       | Check whether an item exists in a fixed array.                      |\n| count          | Return the number of elements.                                      |\n| create         | Create a new fixed array of a given size.                           |\n| dsfargeg       | DSFARGEG                                                            |\n| each           | Apply a callback to each item without modifying the original array. |\n| every          | Determine if all items pass a given test.                           |\n| fill           | Fill the array with a single value.                                 |\n| filter         | Filter the array using a callback (passes key to callback).         |\n| find           | Return the first element matching a callback.                       |\n| findKey        | Return the key of the first element matching a callback.            |\n| findIndex      | Alias for findKey.                                                  |\n| first          | Return the first element of the array.                              |\n| flatten        | Flatten nested arrays, collections, and fixed arrays.               |\n| fluent         | Creates a new fluent interface for chaining methods.                |\n| fromArray      | Create a fixed array from a standard array.                         |\n| fromCollection | Create a fixed array from an Illuminate collection.                 |\n| getSize        | Return the number of elements in the array.                         |\n| implode        | Alias for join.                                                     |\n| isEmpty        | Check if the array is empty.                                        |\n| isFixedArray   | Check whether a value is a fixed array.                             |\n| isNotEmpty     | Check if the array is not empty.                                    |\n| join           | Join array elements with a string.                                  |\n| keys           | Get all keys (indices) from the array.                              |\n| last           | Return the last element of the array.                               |\n| map            | Apply a callback to each item and return a new array.               |\n| max            | Find the maximum value.                                             |\n| merge          | Merge multiple arrays, fixed arrays, or collections.                |\n| min            | Find the minimum value.                                             |\n| nullify        | Replace all elements with null.                                     |\n| offsetExists   | Check if an index exists in the array.                              |\n| offsetGet      | Get the value at a specific index.                                  |\n| offsetNull     | Set a specific index to null.                                       |\n| offsetSet      | Set a value at a specific index.                                    |\n| partition      | Split array into two groups based on a callback.                    |\n| pipe           | Pass the array through a callback and return the result.            |\n| pluck          | Extract values from a specific property or key.                     |\n| pop            | Remove and return the last element.                                 |\n| push           | Add a value to the first available space.                           |\n| random         | Return a random element from the array.                             |\n| reduce         | Reduce the array to a single value using a callback.                |\n| reject         | Filter out items that pass the test (opposite of filter).           |\n| resize         | Alias for setSize.                                                  |\n| reverse        | Reverse the order of elements.                                      |\n| second         | Return the second element.                                          |\n| setSize        | Resize the array to a given size.                                   |\n| shift          | Remove and return the first element.                                |\n| shuffle        | Shuffle the array in a secure manner.                               |\n| slice          | Return a subset of the array.                                       |\n| some           | Determine if at least one item passes a given test.                 |\n| sort           | Sort the array optionally using a callback.                         |\n| sum            | Sum all numeric values in the array.                                |\n| tap            | Pass the array to a callback and return the array.                  |\n| toArray        | Convert the fixed array into a standard PHP array.                  |\n| toCollection   | Convert the fixed array into an Illuminate collection.              |\n| unique         | Remove duplicate values from the array.                             |\n| unshift        | Prepend one or more values to the array.                            |\n| unless         | Apply callback if the condition is false.                           |\n| values         | Get all values from the array (reindexed).                          |\n| when           | Apply callback if the condition is true.                            |\n\n## Testing\n\nTests are run using Pest. You can run the suite like so:\n\n```bash\ncomposer test\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nWe welcome pull requests, especially those improving the package's optimisation and speed, and new\nfeatures to bring it into parity with Collection.\n\nPlease ensure any functionality submitted has adequate test coverage and documentation (at least in English.)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foliverearl%2Ffixed-array-functions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foliverearl%2Ffixed-array-functions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foliverearl%2Ffixed-array-functions/lists"}