Contributed by Grégoire Pineau in #32742 .

The Console component includes some features to output tables and configure them in many different ways. In Symfony 4.4 we've improved it with new types of tables.

Horizontal Tables¶

Consider the following table:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 use Symfony\Component\Console\Command\Command ; use Symfony\Component\Console\Helper\Table ; use Symfony\Component\Console\Input\InputInterface ; use Symfony\Component\Console\Output\OutputInterface ; // ... class SomeCommand extends Command { public function execute ( InputInterface $input , OutputInterface $output ) { $table = new Table ( $output ); $table -> setHeaders ([ 'ISBN' , 'Title' , 'Author' ]) -> setRows ([ [ '99921-58-10-7' , 'Divine Comedy' , 'Dante Alighieri' ], [ '9971-5-0210-0' , 'A Tale of Two Cities' , 'Charles Dickens' ], [ '960-425-059-0' , 'The Lord of the Rings' , 'J. R. R. Tolkien' ], [ '80-902734-1-6' , 'And Then There Were None' , 'Agatha Christie' ], ]) ; $table -> render (); } }

This is displayed as:

1 2 3 4 5 6 7 8 +---------------+--------------------------+------------------+ | ISBN | Title | Author | +---------------+--------------------------+------------------+ | 99921-58-10-7 | Divine Comedy | Dante Alighieri | | 9971-5-0210-0 | A Tale of Two Cities | Charles Dickens | | 960-425-059-0 | The Lord of the Rings | J. R. R. Tolkien | | 80-902734-1-6 | And Then There Were None | Agatha Christie | +---------------+--------------------------+------------------+

If you call to the new setHorizontal(bool $horizontal = true) method, the table is transformed into an "horizontal table", where the data is displayed in rows instead of columns:

1 2 3 4 5 6 7 $table -> setHeaders ([ 'ISBN' , 'Title' , 'Author' ]) -> setRows ([ // ... the rows ... ]) -> setHorizontal () ;

1 2 3 4 5 +--------+-----------------+----------------------+-----------------------+--------------------------+ | ISBN | 99921-58-10-7 | 9971-5-0210-0 | 960-425-059-0 | 80-902734-1-6 | | Title | Divine Comedy | A Tale of Two Cities | The Lord of the Rings | And Then There Were None | | Author | Dante Alighieri | Charles Dickens | J. R. R. Tolkien | Agatha Christie | +--------+-----------------+----------------------+-----------------------+--------------------------+

When using the Symfony style for commands you can also use the horizontalTable() shortcut: