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

Flattening

flatten

Definition

Arr::flatten(array $array, ?int $depth = null, bool $assoc = false): array

Description

Flatten array of arrays to a n-depth array

Examples

$array = [
    'a' => [
        'b' => [
            'c' => 'test'
        ],
        'd' => 1
    ],
    'b' => [
        'e' => 2
    ]
];

Arr::flatten($array) -> 
[
    'test', 
    1, 
    2
]
Arr::flatten($array, 1) -> 
[
    ['c' => 'test'], 
    1, 
    2
]
Arr::flatten($array, 0) -> 
[
    [
        'b' => [
            'c' => 'test'
        ],
        'd' => 1
    ],
    [
        'e' => 2
    ]
]

Arr::flatten([[[[]]]]) -> []

// When $assoc is set to true this method will try to preserve as much string keys as possible using automatically generated numeric indexes as fallback
Arr::flatten($array, null, true) -> 
[
    'c' => 'test', 
    'd' => 1, 
    'e' => 2
]

$array = [
    'a' => [
        'b' => [
            'c' => 1,
        ],
    ],
    [
        'c' => 2
    ]
];

// Here key 'c' is duplicated so it will fallback to numeric index
Arr::flatten($array, null, true) ->
[
    'c' => 1,
    2,
]

flattenSingle

Definition

Arr::flattenSingle(array $array): array

Description

Flatten single element arrays (also nested single element arrays)

Examples

$array = [
    'a' => ['test'],
    'b' => [
        'test2',
        'c' => ['test3']
    ]
];

Arr::flattenSingle($array) ->
[
    'a' => 'test',
    'b' => [
        'test2',
        'c' => 'test3'
    ],
]

$array = [
    'a' => [
        'b' => 1
    ],
    'b' => 2,
];

Arr::flattenSingle($array) -> ['a' => 1, 'b' => 2]

Arr::flattenSingle([['a']]) -> ['a']

Arr::flattenSingle([]) -> []
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