Download the PHP package twelver313/rich-array without Composer
On this page you can find all versions of the php package twelver313/rich-array. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download twelver313/rich-array
More information about twelver313/rich-array
Files in twelver313/rich-array
Package rich-array
Short Description Improved array constructor with additional methods
License MIT
Informations about the package rich-array
RichArray
RichArray is a PHP library designed to bring the flexibility and familiarity of JavaScript's array methods to PHP. It allows developers, especially those coming from JavaScript, to work with arrays in PHP using methods like forEach
, filter
, find
, and more—all.
Features
- Access elements using array-like syntax (e.g.,
$richArray[0]
) - JavaScript-style methods like
forEach
,filter
,find
, and more - Fully compatible with PHP's array access and
foreach
loops - Easily extensible for additional custom methods
Installation
You can install the package via Composer:
Usage
Basic Example
Here’s how you can use RichArray to make your PHP arrays behave more like JavaScript arrays:
Methods Overview
forEach(callable $callback): void
Iterate over each element, just like JavaScript's Array.prototype.forEach()
.
find(callable $callback): mixed
Find and return the first element that matches the condition.
filter(callable $callback): RichArray
Filter elements and return a new RichArray
with the matched elements.
Full API
getLength()
orlength
toRaw()
- library specific methodat(int $index)
include($value)
indexOf($value)
lastIndexOf($value)
push(...$values)
pop()
unshift(...$values)
shift()
join(string $delimiter = '')
concat(array ...$array)
slice(int $offset, int $length)
splice(int $offset, int $length, array $replacement = [])
forEach(callable $callback)
filter(callable $callback)
map(callable $callback)
reduce(callable $callback)
reduceRight(callable $callback)
findEntry(callbable $callback)
find(callable $callback)
findIndex(callable $callback)
findLastEntry(callbable $callback)
findLast(callable $callback)
findLastIndex(callable $callback)
some(callable $callback)
every(callable $callback)
sort(callable $callback)
reverse(bool $preserve_key)
toSorted(callable $callback)
toReversed(bool $preserve_key)
Why RichArray?
RichArray is perfect for developers coming from a JavaScript background who miss the convenience of JavaScript's array methods while working in PHP. This library aims to ease the transition by providing familiar functionality in a PHP-friendly way.
With RichArray, you can enjoy:
- Cleaner, more readable code
- Familiar methods and practices
- No need to reinvent array operations in PHP
License
This library is open-sourced software licensed under the MIT license.
This README introduces RichArray, highlights its usefulness for JavaScript developers, and provides basic examples to get started. It should make it clear how to install and use the library, as well as showcase its immutability and similarity to JavaScript array methods.