PHP code example of softwarecuisine / csv-boolean-cast
1. Go to this page and download the library: Download softwarecuisine/csv-boolean-cast 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/ */
softwarecuisine / csv-boolean-cast example snippets
use SoftwareCuisine\CSVBooleanCast\CSVBooleanCast;
class CSVReader
{
public function read(): void
{
$csv = "id,name,company
1,Test GmbH,WAHR
2,Herr Schmidt,FALSE
3,Beispiel UG,WAHR";
$result = [];
$rows = explode(PHP_EOL, $csv);
foreach ($rows as $index => $row) {
if ($index > 0) {
$columns = str_getcsv(trim($row));
$result[] = CSVBooleanCast::cast($columns[2]);
}
}
var_dump($result);
}
}
(new CSVReader)->read();