Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.
/ array-fold Public archive

Recursively fold a multidimensional array into a unidimensional array, optionally preserving keys

License

Notifications You must be signed in to change notification settings

danielsdeboer/array-fold

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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).

About

Recursively fold a multidimensional array into a unidimensional array, optionally preserving keys

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages