1. Go to this page and download the library: Download g105b/phpcsv 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/ */
$csv = new Csv("/path/to/file.csv");
$resultRows = $csv->getAllBy("gender", "F"); // array of all matching rows.
$firstRow = $csv->getBy("gender", "F"); // single row, first matching.
$csv = new Csv("/path/to/file.csv");
foreach ($csv as $rowNumber => $row) {
// $row is an associative array with CSV headers as each key.
// $rowNumber starts from 1 (ignoring header row).
}
$csv = new Csv("/path/to/file.csv");
$row = $csv->getBy("email", "[email protected]");
// Update the matching row with provided fields, keeping any
// existing field data on the existing row.
$csv->update($row, [
"dateOfBirth" => "1961-08-04",
]);
$csv = new Csv("/path/to/file.csv");
// Delete a row by its index.
$csv->deleteRow(22);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.