jaroslavtyc/drd-plus-therugist-spells

View on GitHub
DrdPlus/Theurgist/Spells/ToFlatArrayTrait.php

Summary

Maintainability
A
35 mins
Test Coverage
<?php
declare(strict_types=1);

namespace DrdPlus\Theurgist\Spells;

trait ToFlatArrayTrait
{
    /**
     * @param array $items
     * @return array
     */
    protected function toFlatArray(array $items): array
    {
        $flat = [];
        foreach ($items as $item) {
            if (\is_array($item)) {
                foreach ($this->toFlatArray($item) as $subItem) {
                    $flat[] = $subItem;
                }
            } else {
                $flat[] = $item;
            }
        }

        return $flat;
    }
}