aviator/array-fold

This package is abandoned and no longer maintained. No replacement package was suggested.

Fold all elements of a multidimentional array down to a single level.

0.1.0 2017-11-25 20:19 UTC

This package is auto-updated.

Last update: 2024-04-21 19:55:54 UTC


README

Latest Stable Version License Build Status

Overview

array_fold() takes an multidimensional array of any depth and recursively folds each level into the previous, flattening it to a single level.

By default it preserves (and overwrites) keys, though this can be disabled with the optional second parameter.

Installation

Via Composer:

composer require aviator/array-fold

Testing

Via Composer:

composer test

Usage

$array = [
    'level1' [
        'some' => 'value',
        'someOther' => 'value',
        'level2' => [
            'someOther' => 'value'
        ]
    ]
];

// Using keys
echo array_fold($array);

/*
 [
    'some' => 'value',
    'someOther' => 'value',
 ]
*/

// Ignoring keys
echo array_fold($array, false);

/*
 [
    'value',
    'value',
    'value',
 ]
*/

Other

License

This package is licensed with the MIT License (MIT).