phplucidframe / console-table

ConsoleTable helps you to display tabular data in a terminal/shell/console
Other
99 stars 22 forks source link

Request: One line array to table wrapper function #3

Closed rgoodie closed 7 years ago

rgoodie commented 7 years ago

Any chance we could put something akin to this as a function?

function table_me($table_data ) {
    $table = new LucidFrame\Console\ConsoleTable();
    $table->addHeader(array_keys($table_data[0]));
    foreach ($table_data as $row) { 
        $table->addRow(@array_values($row));
    }
    $table->display();
}

That could give an one-liner method to produce a table form an associative array.

cithukyaw commented 7 years ago

You could use setHeaders() to add headers for each column in one-line.

$table->setHeaders(array_keys($table_data[0]));

Please check the example.