Hi,
I want to grab data from a .csv file and add all the data to the array. I have the part where I'm grabbing the data from the .csv file but the array issue I haven't totally figured out.
Currently, I'm not adding all the data just the last row of data to the array and need help trying to add all the data to the array. Can someone please help me accomplish this. This is what I have:
[PHP]
global $info;
ini_set("auto_d etect_line_endi ngs", 1);
$current_row = 1;
$handle = fopen("adduser. csv", "r");
$info="";
while ( ($data = fgetcsv($handle , 10000, ",") ) !== FALSE )
{
$number_of_fiel ds = count($data);
if ($current_row == 1)
{
//Header line
for ($c=0; $c < $number_of_fiel ds; $c++)
{
$header_array[$c] = $data[$c];
}
}
else
{
//Data line
for ($c=0; $c < $number_of_fiel ds; $c++)
{
$data_array[$header_array[$c]] = $data[$c];
}
print_r($data_a rray);
$info = $data_array;
}
$current_row++;
}
//buildBatchXML($ data_array);
echo "<br><br>Th is is new data:<br><br>";
foreach($info as $key => $value)
{
echo "$key - $value<br>";
}
fclose($handle) ;
?>
[/PHP]
I want to grab data from a .csv file and add all the data to the array. I have the part where I'm grabbing the data from the .csv file but the array issue I haven't totally figured out.
Currently, I'm not adding all the data just the last row of data to the array and need help trying to add all the data to the array. Can someone please help me accomplish this. This is what I have:
[PHP]
global $info;
ini_set("auto_d etect_line_endi ngs", 1);
$current_row = 1;
$handle = fopen("adduser. csv", "r");
$info="";
while ( ($data = fgetcsv($handle , 10000, ",") ) !== FALSE )
{
$number_of_fiel ds = count($data);
if ($current_row == 1)
{
//Header line
for ($c=0; $c < $number_of_fiel ds; $c++)
{
$header_array[$c] = $data[$c];
}
}
else
{
//Data line
for ($c=0; $c < $number_of_fiel ds; $c++)
{
$data_array[$header_array[$c]] = $data[$c];
}
print_r($data_a rray);
$info = $data_array;
}
$current_row++;
}
//buildBatchXML($ data_array);
echo "<br><br>Th is is new data:<br><br>";
foreach($info as $key => $value)
{
echo "$key - $value<br>";
}
fclose($handle) ;
?>
[/PHP]
Comment