Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Quick PHP table output for console
* A quick way, with a bit of overhead, to get nice tabular output
* from a PHP CLI app.
* Sometimes I find myself just requiring very quick and dirty
* tabular output and find this to be the path of least resistance.
* This method utilises Symfony's Console's Table and BufferedOutput
* classes to generate the table and capture the built table to later
* store or output.
* $ composer require symfony/console
require 'vendor/autoload.php';
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Output\BufferedOutput;
$output = new BufferedOutput();
$table = new Table($output);
$table->setHeaders(['First Name', 'Last Name'])
['John', 'Smith'],
['Jane', 'Doe']
echo $output->fetch();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment