Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Array Laravel Package

minwork/array

Minwork Array provides fast, well-tested helpers for nested, associative, and object arrays. Get/set/has plus map, filter, find, group, sort, and validation, with fluent-style chaining. No dependencies; modern PHP syntax.

View on GitHub
Deep Wiki
Context7
v1.13.1

set method now also allow to supply object implementing ArrayAccess instead of pure array as first argument, as well as handling nested ArrayAccess objects.

v1.13.0

Added new mode to check method that enables checking if only one of the array elements meet specified condition.

Also greatly improved check documentation - https://minwork.gitbook.io/array/validating-array/check

v1.12.0

Added Arr::filter method which is a wrapper around array_filter to allow chaining in ArrObj

v1.11.0

Added method to traverse through array or iterable object without modifying it. More info in documentation: https://minwork.gitbook.io/array/traversing-array/iterating

v1.10.0

Added method to find element(s) inside an array or iterable object. More info in documentation: https://minwork.gitbook.io/array/manipulating-array/finding

v1.9.0

Added new class ArrObj which can be used to easily chain Arr methods.

ArrObj instance can be obtained by either explicitly calling it's constructor with new ArrObj(...) or for even easier chaining Arr::obj(...) method.

Examples:

// Chain setting nested array values
Arr::obj()->set('foo', 'bar')->set('test.[]', 'test')->getArray() ->
[
  'foo' => 'bar', 
  'test' => ['test']
]

// Quickly flatten array of objects grouped by id
Arr::obj([...])->groupObjects('getId')->flattenSingle()->getArray()

What's more, ArrObj contain PHPDoc for every method that can be used in it, so you can take advantage of your editor autocomplete feature.

Full documentation of this feature, coming soon.

v1.8.0

Added new Arr::map mode (MAP_ARRAY_VALUE_KEY) to resemble native array_map but with array as first argument and callback as second.

Also added 4 new utility methods for getting first and last key or value from array:

  • getFirstKey
  • getLastKey
  • getFirstValue
  • getLastValue
v1.7.1

setNestedElement / set

  • Fixed error when passing empty $keys
  • Dropped cloning input array to preserve original object references in returned array

remove

  • Dropped cloning input to preserve original object references in returned array
v1.7.0

has

New method

Check if (nested) element with specified keys exists in array

Documentation

remove

New method

Remove (nested) element from array at path specified by keys

Documentation

setNestedElement

Added alias set

getNestedElement

Added alias get

v1.6.0

Pack

Inverse of unpack method.

Unpack

Updated documentation regarding new modes.

v1.5.1

Unpack

  • Replaced internal method argument with mode argument
  • Added 4 modes of handling array at highest nesting depth
    • UNPACK_ALL (default) - unpack every nested array
      $arr['foo.bar.0'] = 'a';
      $arr['foo.bar.1'] = 'b';
      
    • UNPACK_PRESERVE_LIST_ARRAY - preserve list type array
      $arr['foo.bar'] = ['a', 'b'];
      
    • UNPACK_PRESERVE_ASSOC_ARRAY - preserve associative array
      $arr['foo.bar'] = ['a' => 1, 'b' => 2];
      
    • UNPACK_PRESERVE_ARRAY - work as both of options above combined
  • For examples check out unpack test method testUnpack
  • Examples in documentation coming soon

isAssoc

  • Clarified in PHPDoc how both values of $strict flag works
v1.5.0

isNested

Check if any element of an array is also an array.

For example [1, 2, 3] is a regular array so it isn't nested and [1, 2 => [], 3] has another array as one of it's elements so it is nested.

getDepth

Get nesting depth of an array.

Taking example from above, [1, 2, 3] is a regular array so it has depth of 1 and [1, 2 => [], 3] has depth of 2 because of a second array in it. More detailed examples showing more complex cases can be found in documentation.

v1.4.0

Calculate intersection between two or more arrays of objects using objects hashes for comparison.

v1.3.0

New method sortObjects can be used for sorting array of objects by supplying method name (possibly with method arguments) to call on every object in array

v1.2.0

Unpack

  • Added unpack method to easily convert multidimensional arrays to flat map of keys concatenated by dot and corresponding values

Map

New functionality

  • Now map method handles multidimensional arrays with ease using one of three modes
    • MAP_ARRAY_KEY_VALUE - Basic mapping supplying callback with current element key as 1st argument and value as 2nd
    • MAP_ARRAY_VALUE_KEYS_LIST - Multidimensional mapping supplying callback with current element value as 1st argument and element keys as subsequent arguments
    • MAP_ARRAY_KEYS_ARRAY_VALUE - Multidimensional mapping supplying callback with array of current element keys as 1st argument and element value as 2nd

Arguments order depreciation

  • Map method now accepts array as 1st argument and callback as 2nd issuing appropriate deprecation warning when using old syntax (callback as 1st and array as 2nd)

For use cases check out updated examples section

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours