componenta/array

Array helper functions for Componenta packages

Maintainers

Package info

github.com/componenta/array

pkg:composer/componenta/array

Statistics

Installs: 7

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-06-15 10:54 UTC

This package is auto-updated.

Last update: 2026-06-15 12:06:31 UTC


README

Standalone array helper functions for key checks, nested paths, filtering, mapping, sorting, grouping, recursive transforms, query-string building, and conversion to plain arrays.

Use this package when a library needs predictable array utilities without pulling in a larger collection component.

Installation

composer require componenta/array

Related Packages

Package Why it matters here
componenta/arrayable to_array() consumes ArrayableInterface when an object exposes an array representation.
componenta/config Often works with nested arrays and paths, while configuration access itself stays in componenta/config.

Usage

use function Componenta\Array\array_get;
use function Componenta\Array\array_path;
use function Componenta\Array\array_set_path;

$data = ['user' => ['name' => 'Ada']];

$name = array_path($data, 'user.name');       // "Ada"
$missing = array_get($data, 'email', 'none'); // "none"

array_set_path($data, 'user.email', 'ada@example.com');

Helper Groups

Lookup helpers:

  • array_has
  • array_has_any
  • array_has_all
  • array_missing
  • array_get
  • array_get_typed
  • array_get_or_fail
  • array_path
  • array_path_or_fail

Mutation helpers:

  • array_put
  • array_add
  • array_set
  • array_set_path
  • array_forget
  • array_forget_path
  • array_pull

Selection and transformation:

  • array_only
  • array_except
  • array_where
  • array_map_with_keys
  • array_map_recursive
  • array_filter_null
  • array_pluck
  • array_group_by
  • array_key_by
  • array_partition

Structure helpers:

  • array_flatten
  • array_collapse
  • array_dot
  • array_undot
  • array_divide
  • array_wrap
  • array_chunk_by

Ordering and set-like helpers:

  • array_sort
  • array_sort_recursive
  • array_shuffle
  • array_random
  • array_unique_by
  • array_diff_assoc_recursive
  • array_merge_recursive_distinct

Predicate helpers:

  • array_contains
  • array_first
  • array_last
  • array_find_key
  • array_every
  • array_some
  • array_exists
  • array_is_assoc
  • is_accessible

Other helpers:

  • array_join
  • array_take
  • array_skip
  • array_query
  • to_array

Conversion

to_array() understands arrays, objects, iterators, iterator aggregates, and Componenta\Arrayable\Arrayable.

The package does not define serialization policy for domain objects. If an object has application-specific output rules, expose them through Arrayable or a serializer layer.