PHP code example of smrtr / datagrid
1. Go to this page and download the library: Download smrtr/datagrid 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/ */
smrtr / datagrid example snippets
use Smrtr\DataGrid;
$grid = new DataGrid(
array(
array("First name", "Last Name", "Position", "Age"),
"WR" => array("Wayne", "Rooney", "striker", 27),
"KG" => array("Kieran", "Gibbs", "left back", 23),
"GB" => array("Gareth", "Barry", "midfielder", 32),
"TW" => array("Theo", "Walcott", "striker", 24)
),
DataGrid::ASSOC_COLUMN_FIRST,
DataGrid::ASSOC_ROW_KEYS
);
$grid->saveCSV('/path/to/file.csv');
$grid->serveJSON('download.json');
$grid2 = new DataGrid;
$grid2->loadCSV('/path/to/file.csv', true, true);
print_r(
$grid
->searchRows('Age<25 + Position=striker')
->getRowLabels()
); // [ "TW" ]
print_r(
$grid
->searchRows('Age<25 - Position=striker')
->getRowLabels()
); // [ "KG" ]
print_r(
$grid
->searchRows('Age<30 + (Position="left back" , Position=midfielder)')
->getRowLabels()
); // [ "KG" ]
print_r(
$grid
->searchRows('(Age<30 + Position="left back") , Position=midfielder')
->getRowLabels()
); // [ "KG", "GB" ]
echo $grid->row('WR')['First name']; // "Wayne"
$grid->renameColumn('First name', 'Forename');
$s = serialize($grid);
$grid = unserialize($s);
$inverse = $grid->transpose();
echo ($grid->getRowKeys() === $inverse->getColumnKeys()) ? 'Y' : 'N'; // "Y"