aviator/array-fold

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: 2020-07-21 10:51:10 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).