protected static function generateContentArray($contentRows, $keys, $generateHeader = true)
    {
        if (is_scalar($contentRows)) {
            throw new Exception("Content must be either an array, object or traversable");
        }

        $attributeKeys = $keys;
        $header = [];
        $rows = [];
        $i = 0;
        foreach ($contentRows as $content) {
            // handle rows content
            if (!empty($keys) && is_array($content)) {
                foreach ($content as $k => $v) {
                    if (!in_array($k, $keys)) {
                        unset($content[$k]);
                    }
                }
            } elseif (!empty($keys) && is_object($content)) {
                $attributeKeys[get_class($content)] = $keys;
            }
            $rows[$i] = ArrayHelper::toArray($content, $attributeKeys, false);

            // handler header
            if ($i == 0 && $generateHeader) {
                if ($content instanceof ActiveRecordInterface) {
                    foreach ($content as $k => $v) {
                        if (empty($keys)) {
                            $header[] = $content->getAttributeLabel($k);
                        } elseif (in_array($k, $keys)) {
                            $header[] = $content->getAttributeLabel($k);
                        }
                    }
                } else {
                    $header = array_keys($rows[0]);
                }
            }

            $i++;
        }

        if ($generateHeader) {
            return ArrayHelper::merge([$header], $rows);
        }

        return $rows;
    }
protected static function generateContentArray($contentRows, $keys, $generateHeader = true)
    {
        if (is_scalar($contentRows)) {
            throw new Exception("Content must be either an array, object or traversable");
        }

        $attributeKeys = $keys;
        $header = [];
        $rows = [];
        $i = 0;
        foreach ($contentRows as $content) {
            // handle rows content
            if (!empty($keys) && is_array($content)) {
                foreach ($content as $k => $v) {
                    if (!in_array($k, $keys)) {
                        unset($content[$k]);
                    }
                }
            } elseif (!empty($keys) && is_object($content)) {
                $attributeKeys[get_class($content)] = $keys;
            }
            $rows[$i] = ArrayHelper::toArray($content, $attributeKeys, false);

            // handler header
            if ($i == 0 && $generateHeader) {
                if ($content instanceof ActiveRecordInterface) {
                    foreach ($content as $k => $v) {
                        if (empty($keys)) {
                            $header[] = $content->getAttributeLabel($k);
                        } elseif (in_array($k, $keys)) {
                            $header[] = $content->getAttributeLabel($k);
                        }
                    }
                } else {
                    $header = array_keys($rows[0]);
                }
            }

            $i++;
        }

        if ($generateHeader) {
            return ArrayHelper::merge([$header], $rows);
        }

        return $rows;
    }
protected static function generateContentArray ( $ contentRows , $ keys , $ generateHeader = true ) { if ( is_scalar ( $ contentRows ) ) { throw new Exception ( "Content must be either an array, object or traversable" ) ; } $ attributeKeys = $ keys ; $ header = [ ] ; $ rows = [ ] ; $ i = 0 ; foreach ( $ contentRows as $ content ) { // handle rows content if ( ! empty ( $ keys ) && is_array ( $ content ) ) { foreach ( $ content as $ k => $ v ) { if ( ! in_array ( $ k , $ keys ) ) { unset ( $ content [ $ k ] ) ; } } } elseif ( ! empty ( $ keys ) && is_object ( $ content ) ) { $ attributeKeys [ get_class ( $ content ) ] = $ keys ; } $ rows [ $ i ] = ArrayHelper :: toArray ( $ content , $ attributeKeys , false ) ; // handler header if ( $ i == 0 && $ generateHeader ) { if ( $ content instanceof ActiveRecordInterface ) { foreach ( $ content as $ k => $ v ) { if ( empty ( $ keys ) ) { $ header [ ] = $ content -> getAttributeLabel ( $ k ) ; } elseif ( in_array ( $ k , $ keys ) ) { $ header [ ] = $ content -> getAttributeLabel ( $ k ) ; } } } else { $ header = array_keys ( $ rows [ 0 ] ) ; } } $ i ++ ; } if ( $ generateHeader ) { return ArrayHelper :: merge ( [ $ header ] , $ rows ) ; } return $ rows ; }
Generate content by rows.

@param array $contentRows
@param string$delimiter
@param string $keys
@param bool $generateHeader
@return array
@throws Exception
@since 1.0.4
Generate content by rows .