It's a mistake--it's already known.
Just don't know how to change
PHP Code
$V) {if ($k = = $c)//The corresponding field {$d ata[$v] = $DATASRC [$c]; }}}} if (!empty ($data)) {$dataRtn [] = $data; Unset ($data); } $row + +; } fclose ($handle); return $dataRtn; }}function Print_array ($data)//error in this function {$row = count ($data); $column = count ($data [0]); Echo $row; Echo $column; echo "
"; for ($i =0; $i < $row; $i + +) {echo "
"; for ($j =0; $j < $column; $j + +) {echo "
"; echo $data [$i] [$j]; echo " | "; } echo "
"; } echo "
";} $aData = Getcsvdata (' test.csv '),//print_r ($aData);p Rint_array ($aData);? >
Because you want to read the table information in the relevant Excel file from the CSV file, and want to display them in the same way as the index number [$i] [$j].
But the problem is that $J is not the index of the actual column of the data table, because in my file, the names of the individual columns are actually "wages 1", "Wages 2", "Wages 3" ...
A Chinese name like this one. So it shows undefined offset:0 in C:\inetpub\wwwroot\test\fileRead.php on line 54 like this error
So I want to ask this question how to solve: when I do not know the column index key, how can I take the index number to separate them out?
Because in the actual function, I need to query the database according to the name of this column, and insert the corresponding column value into the corresponding Name column of database table.
For example, $data[i]["Payroll 1" is inserted into the "Payroll 1" column of the data table, so you must be able to remove the string "wage 1", and the corresponding array element is also a single order to take out.
------Solution--------------------
Using the Foreach Loop
You'd better put out $aData, with Var_export ($aData)
------Solution--------------------
Iterate through the array, commonly used
foreach ($arr as $k + $v)//$k subscript, $v value
{
}
Or the while list iterates through the array
------Solution--------------------
foreach ($data [$i] as $k = = $v)//$K is the column name