1<?php
2
3//Open our CSV file using the fopen function.
4$fh = fopen("names.csv", "r");
5
6//Setup a PHP array to hold our CSV rows.
7$csvData = array();
8
9//Loop through the rows in our CSV file and add them to
10//the PHP array that we created above.
11while (($row = fgetcsv($fh, 0, ",")) !== FALSE) {
12 $csvData[] = $row;
13}
14
15//Finally, encode our array into a JSON string format so that we can print it out.
16echo json_encode($csvData);
17