Reading CSV File into PHP ARRAY

reading csv into php array

Using PHP to read CSV files
A Comma-separated values (CSV) file stores tabular data (numbers and text) in plain-text form. Often it is one record per line separated by a comma or any other delimiter. The comma , is often used in USA/UK CSV files where Germany often uses a ; instead.

>> Learn more about PHP ARRAYS here <<

This is an example of a simple CSV file that has 4 fields and 2 records (1 per line).

In PHP it is often useful to be able to read a CSV file and access it’s data. That is where the fgetcsv() function comes in handy, it will read each line of a CSV file and assign each value into an ARRAY. You can define the separator in the function as well see PHP docs for fgetcsv() for more options and examples.

>> Learn more about PHP ARRAYS here <<

Here is a simple function that shows how to read our CSV file and return an ARRAY holding the data from the CSV.

>> Learn more about PHP ARRAYS here <<

>> Learn more about PHP ARRAYS here <<