PHP Library for converting associative arrays as html table, XML, JSON, CSV. Also add, remove or edit column can be possible.
Inspired by yajra/laravel-datatables
Install the library by composer with following command:
composer install samad/array-conversionAn associative/ multidimensional array or object can be manipulate with this script. You can convert the array/ object to HTML table, CSV file, JSON or XML data.
Suppose, you have an array as like following:
$data = [
[
'name' => 'Abdus Samad',
'email' => '[email protected]'
],
[
'name' => 'Ibrahim Ahad',
'email' => '[email protected]'
]
];now, you can convert this $data as HTML table
$toTableInitiate = new ArrayConversion($data);
$toTableInitiate->toTable()also, this $data can be converted into following formats:
- CSV file
toCSV() - JSON format
toJson() - XML format
toXml()
You can add an extra column by using closure.
As like Action to each single array of $data
$addColumnToTable = new ArrayConversion($data);
$addColumnToTable->addColumn('Action', function ($data) {
return '<button class="btn btn-success btn-xs">Action</button>';
})->toTable();or you can remove single/ multiple column from each single array
$removeColumnFromTable = new ArrayConversion($data);
$removeColumnFromTable->removeColumn('email', 'name')
->toTable();also, you can edit column from each single array
$editColumn = new ArrayConversion($data);
$editColumn->editColumn('email', function ($data) {
return 'Email: ' . $data['email'];
})->toTable();After installation this library, you will see a file index.php with details example.
The MIT License (MIT). Please see License File for more information.