Weave 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

Grouping

group

Definition

Arr::group(array $array, string|int $key): array

Description

Group array of arrays by value of element with specified key

Examples

$array = [
    'a' => ['key1' => 'test1', 'key2' => 1, 'key3' => 'a'],
    'b' => ['key1' => 'test1', 'key2' => 2],
    2 => ['key1' => 'test2', 'key2' => 3, 'key3' => 'b']
];

Arr::group($array, 'key1') -> 
[
    'test1' => [
        'a' => ['key1' => 'test1', 'key2' => 1,  'key3' => 'a'],
        'b' => ['key1' => 'test1', 'key2' => 2]
    ],
    'test2' => [
        2 => ['key1' => 'test2', 'key2' => 3, 'key3' => 'b']
    ],
]

Arr::group($array, 'key2') ->
[
    1 => [
        'a' => ['key1' => 'test1', 'key2' => 1, 'key3' => 'a'],
    ],
    2 => [
        'b' => ['key1' => 'test1', 'key2' => 2]
    ],
    3 => [
        2 => ['key1' => 'test2', 'key2' => 3, 'key3' => 'b']
    ],
]

Arr::group($array, 'key3') ->
[
    'a' => [
        'a' => ['key1' => 'test1', 'key2' => 1,  'key3' => 'a']
    ],
    'b' => [
        2 => ['key1' => 'test2', 'key2' => 3, 'key3' => 'b']
    ],
]

Arr::group($array, 'key4') -> []

groupObjects

Definition

Arr::groupObjects(array $objects, string $method, ...$args): array

Description

Group array of objects by value returned from specified method

Examples

$object1 = new class() { 
    function test() { 
        return 'test1';
    }
};
$object2 = new class() { 
    function test() { 
        return 'test2';
    }
};

Arr::groupObjects([$object1, $object2, $object1], 'test') -> 
[
    'test1' => [$object1, $object1],
    'test2' => [$object2],
]

// This method is also very useful in conjunction with Arr::flattenSingle to assign unique key for each object
Arr::flattenSingle(Arr::groupObjects([$object1, $object2], 'test')) -> 
[
    'test1' => $object1,
    'test2' => $object2,
]
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.
coleus/frame
thtg88/journalism
filagora/filagora-ai-forums
rlacerda83/query-parser
socialdept/atp-orm
cboxdk/laravel-assistant-client
socialdept/atp-resolver
socialdept/tenant-domains
tautvydasr/blade-class-names
socialdept/color-scales
maherelgamil/controller
coleus/widgets
coleus/table
coleus/users
coleus/music
coleus/health
coleus/calendar
coleus/notes
coleus/support
coleus/settings