CsvHelper
in package
FinalYes
CSV file utility class.
Provides methods for reading and writing CSV files with proper encoding support and row manipulation callbacks.
Table of Contents
Methods
- putRow() : void
- Append a row to a CSV file.
- read() : array<string|int, array<string|int, mixed>>|null
- Read all rows from a CSV file.
Methods
putRow()
Append a row to a CSV file.
public
static putRow(string $filePath, array<string|int, mixed> $row) : void
Uses file locking (LOCK_EX) to prevent concurrent write corruption.
Parameters
- $filePath : string
-
CSV file path.
- $row : array<string|int, mixed>
-
Array of field values to write.
Tags
read()
Read all rows from a CSV file.
public
static read(string $filePath[, callable|null $callback = null ]) : array<string|int, array<string|int, mixed>>|null
An optional callback can transform or filter each row. If the callback returns null/empty, the row is excluded.
Parameters
- $filePath : string
-
CSV file path.
- $callback : callable|null = null
-
Row transformer:
function(array $row): ?array. Return null to skip row.
Return values
array<string|int, array<string|int, mixed>>|null —Array of rows, or null if file does not exist or is empty.