It's still a mistake.-the exception is already known.

Source: Internet
Author: User
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 " 
    "; } echo " 
   
"; echo $data [$i] [$j]; 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
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.