Illuminate\Support\Collection::flatten PHP Method

flatten() public method

Get a flattened array of the items in the collection.
public flatten ( integer $depth = INF ) : static
$depth integer
return static
    public function flatten($depth = INF)
    {
        return new static(Arr::flatten($this->items, $depth));
    }

Usage Example

Exemplo n.º 1
0
 public function testFlattenWithDepth()
 {
     // No depth flattens recursively
     $c = new Collection([['#foo', ['#bar', ['#baz']]], '#zap']);
     $this->assertEquals(['#foo', '#bar', '#baz', '#zap'], $c->flatten()->all());
     // Specifying a depth only flattens to that depth
     $c = new Collection([['#foo', ['#bar', ['#baz']]], '#zap']);
     $this->assertEquals(['#foo', ['#bar', ['#baz']], '#zap'], $c->flatten(1)->all());
     $c = new Collection([['#foo', ['#bar', ['#baz']]], '#zap']);
     $this->assertEquals(['#foo', '#bar', ['#baz'], '#zap'], $c->flatten(2)->all());
 }
All Usage Examples Of Illuminate\Support\Collection::flatten