PHP code example of kedrigern / data-table
1. Go to this page and download the library: Download kedrigern/data-table library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
kedrigern / data-table example snippets
$table = new \Kedrigern\DataTable\RecordTable();
$table->loadFromArray(array(
array("Name", "Surname", "Age"),
array("Jane", "Roe", 29),
array("John", "Doe", 30)
));
$table->useFirstRowAsHeader();
// Sum the ages = 59
$ageSum = $table->colSum("Age");
$table->sortByCol("Surname");
$table->callToCol("Surname", 'strtoupper');
$newCol = range(1,$table->getRowsNum());
$table->appendCol($newCol, "Unique");
$newTable = $table->resortColsByNewHeader(array("Unique", "Surname", "Name"));
$table->loadFromCsvFile(__DIR__ . '/../data/data4.csv');
$table->useFirstRowAsHeader();
$map = array(
"Alpha" => "A",
"Beta" => "B",
);
$table2 = $table->renameColumns($map);
$isEven = function($row) {
return ($row[0] % 2) == 0;
};
$removed = $t->removeRowsIf($isEven);
$table->loadFromArray(array(
array("Name", "Surname", "Age", "Born", "Registered"),
array("Jane", "Roe", 29, "1990-1-1", "2013-12-30 01:02:03"),
array("John", "Doe", 30, "1990-1-1", "2014-12-30 01:02:03")
));
$table->useFirstRowAsHeader();
$func = array('\Kedrigern\DataTable\Callback','toDatetime');
$table->callToCol(3, $func, array('Y-m-d', 'M y'));
$table->callToCol(4, $func, array('Y-m-d H:i:s', 'U', 'Europe/London'));
$table->loadFromArray(array(
array("Name", "Surname"),
array("Jane", "Roe"),
array("John", "Doe")
));
$table->joinCols(["Name", "Surname"], "Fullname");
$table->loadFromArray(array(
array("Fullname"),
array("Jane Roe"),
array("John Doe")
));
$table->splitCol("Fullname", ["Name", "Surname"]);