public function normalizeColumns(array &$rows) : array
    {
        $maxNumColumns = 0;

        // Find the max number of columns that appear in any given row
        foreach ($rows as $row) {
            $maxNumColumns = max($maxNumColumns, count($row));
        }

        $maxLengths = array_pad([], $maxNumColumns, 0);

        // Normalize the number of columns in each row
        foreach ($rows as &$row) {
            $row = array_pad($row, $maxNumColumns, '');
        }

        // Get the length of the longest value in each column
        foreach ($rows as &$row) {
            foreach ($row as $column => &$value) {
                $value = trim($value);
                $maxLengths[$column] = max($maxLengths[$column], mb_strlen($value));
            }
        }

        return $maxLengths;
    }
public function normalizeColumns(array &$rows) : array
    {
        $maxNumColumns = 0;

        // Find the max number of columns that appear in any given row
        foreach ($rows as $row) {
            $maxNumColumns = max($maxNumColumns, count($row));
        }

        $maxLengths = array_pad([], $maxNumColumns, 0);

        // Normalize the number of columns in each row
        foreach ($rows as &$row) {
            $row = array_pad($row, $maxNumColumns, '');
        }

        // Get the length of the longest value in each column
        foreach ($rows as &$row) {
            foreach ($row as $column => &$value) {
                $value = trim($value);
                $maxLengths[$column] = max($maxLengths[$column], mb_strlen($value));
            }
        }

        return $maxLengths;
    }
public function normalizeColumns ( array & $ rows ) : array { $ maxNumColumns = 0 ; // Find the max number of columns that appear in any given row foreach ( $ rows as $ row ) { $ maxNumColumns = max ( $ maxNumColumns , count ( $ row ) ) ; } $ maxLengths = array_pad ( [ ] , $ maxNumColumns , 0 ) ; // Normalize the number of columns in each row foreach ( $ rows as & $ row ) { $ row = array_pad ( $ row , $ maxNumColumns , '' ) ; } // Get the length of the longest value in each column foreach ( $ rows as & $ row ) { foreach ( $ row as $ column => & $ value ) { $ value = trim ( $ value ) ; $ maxLengths [ $ column ] = max ( $ maxLengths [ $ column ] , mb_strlen ( $ value ) ) ; } } return $ maxLengths ; }
Normalizes the number of columns in each row

@param array $rows The rows to equalize
@return array The max length of each column
Normalizes the number of columns in each row