Reputation: 81
I tried to export csv files so I got an array like
Array
(
[0] => Name
[1] => Emp Code
[2] => Designation
[3] => Basic
[4] => DA
[5] => HRA
[6] => CCA
[7] => Conveyance
[8] => Others
[9] => Mgt Contr PF
[10] => PL Encashment
[11] => Income Tax
[12] => Prof Tax
[13] => Welfare Fund
)
Array
(
[0] => Li
[1] => 60
[2] => Web Designer
[3] => 14400
[4] => 9600
[5] => 4800
[6] => 4800
[7] => 1600
[8] => 12800
[9] => 800
[10] => 0
[11] => 0
[12] => 0
[13] => 20
)
Here first array values are the csv file column name, so I don't want to save them in database.
Here is my code
while (($data = fgetcsv($file, 1000, ",")) !== FALSE) {
$num = count($data);
for ($c=0; $c < $num; $c++) {
$importData_arr[$i][] = $data[$c];
}
$i++;
}
fclose($file);
$skip = 0;
foreach($importData_arr as $data){
echo '<pre>';print_r($data);
}
}
How can I remove column name from array. Please help me
Upvotes: 1
Views: 86
Reputation: 147256
You can skip the first row by reading it prior to the loop. You can also massively simplify your code:
fgets($file);
while (($data = fgetcsv($file, 1000, ",")) !== FALSE) {
$importData_arr[] = $data;
}
fclose($file);
$skip = 0;
foreach($importData_arr as $data){
echo '<pre>';print_r($data);
}
Upvotes: 3