From 0c38366e929f63d709cda457cdbcd763c6c8ca7d Mon Sep 17 00:00:00 2001 From: Neil Lathwood Date: Sat, 6 May 2017 22:37:33 +0100 Subject: [PATCH] Updated to allow the use of indexes within columns --- lib/cli/Table.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/cli/Table.php b/lib/cli/Table.php index 5a0ff8b..54982f6 100644 --- a/lib/cli/Table.php +++ b/lib/cli/Table.php @@ -27,6 +27,7 @@ class Table { protected $_footers = array(); protected $_width = array(); protected $_rows = array(); + protected $_use_index = false; /** * Initializes the `Table` class. @@ -79,6 +80,7 @@ public function resetTable() $this->_width = array(); $this->_rows = array(); $this->_footers = array(); + $this->_use_index = false; return $this; } @@ -212,6 +214,14 @@ public function addRow(array $row) { $this->_rows[] = $this->checkRow($row); } + /** + * Sets if we should output the arrays index + */ + public function useIndex() + { + $this->_use_index = true; + } + /** * Clears all previous rows and adds the given rows. * @@ -220,7 +230,10 @@ public function addRow(array $row) { */ public function setRows(array $rows) { $this->_rows = array(); - foreach ($rows as $row) { + foreach ($rows as $id => $row) { + if ($this->_use_index === true) { + $row = array_merge(array($id), $row); + } $this->addRow($row); } }