public function extractSubElements(
        array $array,
        bool $preserveKeys = false
    ): array {
        $resultArray = [];

        foreach ($array as $element) {
            if (is_array($element)) {
                foreach ($element as $subKey => $subElement) {
                    if ($preserveKeys) {
                        $resultArray[$subKey] = $subElement;
                    } else {
                        $resultArray[] = $subElement;
                    }
                }
            } else {
                $resultArray[] = $element;
            }
        }

        return $resultArray;
    }
public function extractSubElements(
        array $array,
        bool $preserveKeys = false
    ): array {
        $resultArray = [];

        foreach ($array as $element) {
            if (is_array($element)) {
                foreach ($element as $subKey => $subElement) {
                    if ($preserveKeys) {
                        $resultArray[$subKey] = $subElement;
                    } else {
                        $resultArray[] = $subElement;
                    }
                }
            } else {
                $resultArray[] = $element;
            }
        }

        return $resultArray;
    }
public function extractSubElements ( array $ array , bool $ preserveKeys = false ) : array { $ resultArray = [ ] ; foreach ( $ array as $ element ) { if ( is_array ( $ element ) ) { foreach ( $ element as $ subKey => $ subElement ) { if ( $ preserveKeys ) { $ resultArray [ $ subKey ] = $ subElement ; } else { $ resultArray [ ] = $ subElement ; } } } else { $ resultArray [ ] = $ element ; } } return $ resultArray ; }
This method extracts sub elements to the parent level.

An input array of type:
[
element1 => [
0 => 'value1'
],
element2 => [
0 => 'value2'
1 => 'value3'
],

will be converted to:
[
0 => 'value1'
1 => 'value2'
2 => 'value3'
]

@param array $array        The array
@param bool  $preserveKeys Should the key be preserved, defaults to `false`

@return array
This method extracts sub elements to the parent level .