I want to get the value of column header in getcsv but I can't.
Example inputs:
Name , Address , Age
John , California, 26
Michael, L.A , 29
If I am in row2 column2, I want to get the name of header which is Address. But my code returns as L.A.
This is my code:
<?php
echo '<table class="tbl">';
while(($data = fgetcsv($handle, 1000, ",")) !== false)
{
$col = count($data);
$header = $data[0]; //I AM SUPPOSED to get this value but this returns to the current cell and not the column header.
echo '<tr>';
for ($c=0; $c < $col; $c++) {
$cell = esc_html( $data[$c] );
$colnum = $c + 1;
if( $row == 0)
{
echo "<td style='text-transform:uppercase;'><br><br>".
"<b>{$cell}</b></td>";
}
else
{
echo "<td>{$cell} = {$header}</td>"; //{$row} = {$colnum}
}
}
echo '</tr>';
$row++;
}
echo '</table>';
Based on the inputs and code above, here is the output:
Name , Address , Age
John = John , California = California , 26 = 26
Michael= Michael , L.A = L.A , 29 = 29
I am supposed to get the header value of each column as shown below:
Name , Address , Age
John = Name , California = Address , 26 = Age
Michael= Name , L.A = Address , 29 = Age