PHP code example of erguncaner / table

1. Go to this page and download the library: Download erguncaner/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/ */

    

erguncaner / table example snippets




use erguncaner\Table\Table;
use erguncaner\Table\TableColumn;
use erguncaner\Table\TableRow;
use erguncaner\Table\TableCell;

// Sample data
$posts = [
    ['id'=>1, 'title'=>'Title 1'],
    ['id'=>2, 'title'=>'Title 2'],
    ['id'=>3, 'title'=>'Title 3'],
];

// First create a table
$table = new Table([
    'id'=>'post-table'
]);

// Create table columns with a column key and column object
$table->addColumn('id', new TableColumn('ID', ['class'=>'id-column']));
$table->addColumn('title', new TableColumn('TITLE'));

// Then add rows
foreach($posts as $post){
    
    // Associate cells with columns
    $cells = [
        'id' => new TableCell($post['id'], ['class'=>'id-cell']),
        'title' => new TableCell($post['title']),
    ];

    // define row attributes
    $attrs = [
        'id' => 'post-'.$post['id']
    ];

    $table->addRow(new TableRow($cells, $attrs));
}

// Finally generate html
$html = $table->html();