public function addTable($rows, $headers = false)
	{
		// Figure out some items we need to know
		$maxLengths = [];

		foreach ($rows as $i => $row)
		{
			foreach ($row as $k => $field)
			{
				$maxLengths[$k] = isset($maxLengths[$k]) ? $maxLengths[$k] : 0;
				$maxLengths[$k] = strlen($field) > $maxLengths[$k] ? strlen($field) : $maxLengths[$k];
			}
		}

		// Compute the total length of the table
		$width = array_sum($maxLengths) + ((count($row) - 1) * 3) + 2;

		// Add the top border
		$this->addLine('/' . str_repeat('-', ($width)) . '\\');

		// Draw the rows
		foreach ($rows as $i => $row)
		{
			$styles = ($i == 0 && $headers) ? ['format' => 'underline'] : null;
			foreach ($row as $k => $field)
			{
				$padding = $maxLengths[$k] - strlen($field);
				$this->addString('| ');
				$this->addString($field, $styles);
				$this->addString(' ' . str_repeat(' ', $padding));
			}

			$this->addLine('|');
		}

		// Add the bottom border
		$this->addLine('\\' . str_repeat('-', ($width)) . '/');
	}
public function addTable($rows, $headers = false)
	{
		// Figure out some items we need to know
		$maxLengths = [];

		foreach ($rows as $i => $row)
		{
			foreach ($row as $k => $field)
			{
				$maxLengths[$k] = isset($maxLengths[$k]) ? $maxLengths[$k] : 0;
				$maxLengths[$k] = strlen($field) > $maxLengths[$k] ? strlen($field) : $maxLengths[$k];
			}
		}

		// Compute the total length of the table
		$width = array_sum($maxLengths) + ((count($row) - 1) * 3) + 2;

		// Add the top border
		$this->addLine('/' . str_repeat('-', ($width)) . '\\');

		// Draw the rows
		foreach ($rows as $i => $row)
		{
			$styles = ($i == 0 && $headers) ? ['format' => 'underline'] : null;
			foreach ($row as $k => $field)
			{
				$padding = $maxLengths[$k] - strlen($field);
				$this->addString('| ');
				$this->addString($field, $styles);
				$this->addString(' ' . str_repeat(' ', $padding));
			}

			$this->addLine('|');
		}

		// Add the bottom border
		$this->addLine('\\' . str_repeat('-', ($width)) . '/');
	}
public function addTable ( $ rows , $ headers = false ) { // Figure out some items we need to know $ maxLengths = [ ] ; foreach ( $ rows as $ i => $ row ) { foreach ( $ row as $ k => $ field ) { $ maxLengths [ $ k ] = isset ( $ maxLengths [ $ k ] ) ? $ maxLengths [ $ k ] : 0 ; $ maxLengths [ $ k ] = strlen ( $ field ) > $ maxLengths [ $ k ] ? strlen ( $ field ) : $ maxLengths [ $ k ] ; } } // Compute the total length of the table $ width = array_sum ( $ maxLengths ) + ( ( count ( $ row ) - 1 ) * 3 ) + 2 ; // Add the top border $ this -> addLine ( '/' . str_repeat ( '-' , ( $ width ) ) . '\\' ) ; // Draw the rows foreach ( $ rows as $ i => $ row ) { $ styles = ( $ i == 0 && $ headers ) ? [ 'format' => 'underline' ] : null ; foreach ( $ row as $ k => $ field ) { $ padding = $ maxLengths [ $ k ] - strlen ( $ field ) ; $ this -> addString ( '| ' ) ; $ this -> addString ( $ field , $ styles ) ; $ this -> addString ( ' ' . str_repeat ( ' ' , $ padding ) ) ; } $ this -> addLine ( '|' ) ; } // Add the bottom border $ this -> addLine ( '\\' . str_repeat ( '-' , ( $ width ) ) . '/' ) ; }
Renders rows in a table-like structure

@param   array  $rows     The rows of text to render
@param   bool   $headers  If the first row contains header information
@return  $this
Renders rows in a table - like structure