0
I’m a beginner in php. My code reads a csv file and stores it in an array. The problem is that I can’t access the columns. I’m using php 5.3.3. Does anyone know how to pick up the row and column?
That and my function:
function readCsv($fileName)
{
if(!file_exists($fileName) || !is_readable($fileName)) return false;
$header = null;
$data = array();
$lines = file($fileName);
foreach($lines as $line) {
$values = str_getcsv($line, ',', '\\');
if(!$header) $header = $values;
else $data[] = array_combine($header, $values);
}
return $data;
}
And this is my way out:
Array
(
[Section #] =>
[Q #] => 1
[Q Type] => MAT
[Q Title] =>
[Q Text] => Please rank your 6 preferred sites for your practicum:
[Bonus?] =>
[Difficulty] =>
[Answer] => Boniface (STB)
[Answer Match] => Rank 2
[# Responses] => 0
)
Array
(
[Section #] =>
[Q #] => 1
[Q Type] => MAT
[Q Title] =>
[Q Text] => Please rank your 6 preferred sites for your practicum:
[Bonus?] =>
[Difficulty] =>
[Answer] => Boniface (STB)
[Answer Match] => Rank 2
[# Responses] => 0
)
Array
(
[Section #] =>
[Q #] => 1
[Q Type] => MAT
[Q Title] =>
[Q Text] => Please rank your 6 preferred sites for your practicum:
[Bonus?] =>
[Difficulty] =>
[Answer] => Boniface (STB)
[Answer Match] => Rank 2
[# Responses] => 0
)
You want to access the rows and columns yourself or want to get the values?
– adventistaam