barogue/arrays

A library that extends PHP's native array functionality

1.0.6 2023-08-28 13:29 UTC

This package is auto-updated.

Last update: 2024-04-28 15:09:21 UTC


README

Tests codecov Licence Badge Release Badge Tag Badge Issues Badge Code Size

A library that extends PHP's native array functionality

Compatibility and dependencies

This library is compatible with PHP version 8.1 and 8.2.

This library has no dependencies.

Installation

Installation is simple using composer.

composer require barogue/arrays

Or simply add it to your composer.json file

{
    "require": {
        "barogue/arrays": "^1.0"
    }
}

Contributing

This library follows PSR-1 & PSR-2 standards.

Unit Tests

Before pushing any changes, please ensure the unit tests are all passing.

If possible, feel free to improve coverage in a separate commit.

vendor/bin/phpunit

Code sniffer

Before pushing, please ensure you have run the code sniffer. Only run it using the lowest support PHP version (7.2)

vendor/bin/php-cs-fixer fix

Static Analyses

Before pushing, please ensure you have run the static analyses tool.

vendor/bin/phan

Benchmarks

Before pushing, please ensure you have checked the benchmarks and ensured that your code has not introduced any slowdowns.

Feel free to speed up existing code, in a separate commit.

Feel free to add more benchmarks for greater coverage, in a separate commit.

vendor/bin/phpbench run --report=speed
vendor/bin/phpbench run --report=speed --output=markdown
vendor/bin/phpbench run --report=speed --filter=benchNetFromTax --iterations=50 --revs=50000

vendor/bin/phpbench xdebug:profile
vendor/bin/phpbench xdebug:profile --gui

Documentation

This library adds a number of array functions to extend PHP's native functionality

Below you can find links to the documentation for the new features.

Function Description
array_at Get the nth value from an array
array_deflate Flattens a nested array into a single level array
array_except Return a subset of the array by passing in an array of keys to discard
array_exists Checks if the given key or index exists in the array using dot notation for nested arrays
array_first Get the first item from the array
array_first_key Get the first key from the array
array_get Returns a value from the array, using dot notation for nested sets
array_inflate Expands a flattened array back into a nested array
array_join Joins entries of array into a string using optional glue substring and optional final glue substring
array_key_at Get the nth key from an array
array_last Get the last entry in the array
array_last_key Get the last key in the array
array_only Return a subset of the array by passing in an array of keys to keep
array_pop_many Pop multiple elements off the end of an array
array_pull Return and remove a key in the array using dot notation for nested arrays
array_random Picks one or more random entries out of an array, and returns the value (or values) of the random entries
array_set Set a key in the array using dot notation for nested arrays
array_shift_many Shift multiple elements off the beginning of an array
array_shuffle Shuffle an array, with an option to maintain keys or not
array_unset Remove a key in the array using dot notation for nested arrays