Console_Table examples

Table of Contents

To get the feeling how Console_Table is used, try out the following examples.

A very simple example

Here we are following the basic steps to get some data out on the shell:

  • Creating a Console_Table object

  • Adding the header row

  • Adding some data rows

  • Rendering the table to the shell

<?php
require_once 'Console/Table.php';

$tbl = new Console_Table();
$tbl->setHeaders(
    array(
'Language''Year')
);
$tbl->addRow(array('PHP'1994));
$tbl->addRow(array('C',   1970));
$tbl->addRow(array('C++'1983));

echo 
$tbl->getTable();
?>

This examples would display as following:


+----------+------+
| Language | Year |
+----------+------+
| PHP      | 1994 |
| C        | 1970 |
| C++      | 1983 |
+----------+------+