Arr::flatten

Posted on November 16, 2016

The Arr::flatten function will flatten a multi-dimensional array into a single level.

Example usage

$array = Arr::flatten(['name' => 'Joe', 'languages' => ['PHP', 'Ruby']]);

// ['Joe', 'PHP', 'Ruby']

$array = Arr::flatten([
    ['id' => 1, 'name' => 'John Doe', 'skills' => []],
    ['id' => 2, 'name' => 'Jane Doe', ['skills' => ['smart', 'pretty']]],
]);

// [1, 'John Doe', 2, 'Jane Doe', 'smart', 'pretty']

Parameters

array $array

int $depth

Return Value

array

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *