public function format(array $rows, callable $callback) : string
    {
        foreach ($rows as &$row) {
            $row = (array)$row;
        }

        $maxLengths = $this->normalizeColumns($rows);
        $paddingType = $this->padAfter ? STR_PAD_RIGHT : STR_PAD_LEFT;

        // Format the rows
        foreach ($rows as &$row) {
            foreach ($row as $index => &$item) {
                $item = str_pad($item, $maxLengths[$index], $this->paddingString, $paddingType);
            }
        }

        $formattedText = '';

        foreach ($rows as &$row) {
            $formattedText .= $callback($row) . $this->eolChar;
        }

        // Trim the excess separator
        $formattedText = preg_replace('/' . preg_quote($this->eolChar, '/') . '$/', '', $formattedText);

        return $formattedText;
    }
public function format(array $rows, callable $callback) : string
    {
        foreach ($rows as &$row) {
            $row = (array)$row;
        }

        $maxLengths = $this->normalizeColumns($rows);
        $paddingType = $this->padAfter ? STR_PAD_RIGHT : STR_PAD_LEFT;

        // Format the rows
        foreach ($rows as &$row) {
            foreach ($row as $index => &$item) {
                $item = str_pad($item, $maxLengths[$index], $this->paddingString, $paddingType);
            }
        }

        $formattedText = '';

        foreach ($rows as &$row) {
            $formattedText .= $callback($row) . $this->eolChar;
        }

        // Trim the excess separator
        $formattedText = preg_replace('/' . preg_quote($this->eolChar, '/') . '$/', '', $formattedText);

        return $formattedText;
    }
public function format ( array $ rows , callable $ callback ) : string { foreach ( $ rows as & $ row ) { $ row = ( array ) $ row ; } $ maxLengths = $ this -> normalizeColumns ( $ rows ) ; $ paddingType = $ this -> padAfter ? STR_PAD_RIGHT : STR_PAD_LEFT ; // Format the rows foreach ( $ rows as & $ row ) { foreach ( $ row as $ index => & $ item ) { $ item = str_pad ( $ item , $ maxLengths [ $ index ] , $ this -> paddingString , $ paddingType ) ; } } $ formattedText = '' ; foreach ( $ rows as & $ row ) { $ formattedText .= $ callback ( $ row ) . $ this -> eolChar ; } // Trim the excess separator $ formattedText = preg_replace ( '/' . preg_quote ( $ this -> eolChar , '/' ) . '$/' , '' , $ formattedText ) ; return $ formattedText ; }
Formats rows of text so that each column is the same width

@param array $rows The rows to pad
@param callable $callback The callback that returns a formatted row of text
@return string A list of formatted rows
Formats rows of text so that each column is the same width