I am very newbie to php.I am upto parse the csv file and want to copy selected columns to other csv file, which are not sequential. I have read data from csv file in multidimentional array. so I have all key value pairs, where keys are name of columns and values are the data from csv file. I am using
foreach($contents as $line) {
$line = preg_replace( “/r|n/”, “”, $line );
$line_array = explode(“,”,$line);
if($i==0)
{
foreach($line_array as $key=>$val)
{
$csv_heading[$key] = trim($val);
}
}
else
{
foreach($line_array as $key=>$val)
{
$csv_array[$i][$csv_heading[$key]] = $val;
}
}
$i++;
}
$len = count($csv_array);
$row = array();
for($col = 0 ; $col < $len ; $col++)
{
if(array_intersect_key($col , $picked))
$row[] = $csv_array[$col];
$final = $row;
print_r($row);
}
and my csv file contains records like
name,city,state,country
Dave,mumbai,maharashtra,India
and so on. from the csv file I want to copy the columns name and city to other csv. can anyone help me? Thanks in advance.