0

I wanna import data from CSV file and print it on a webpage using PHP. first I tried it with print_r() it worked perfectly. But, when I tried to print each value in the array individually the error "Array to string conversion" how to prevent this error and access each array value individually? Here is the code

<?php $csv =array_map('str_getcsv', file('kishore.csv'));print_r($csv);echo "\n$csv[0]";?>

Here is the output output

Sri Harsha
  • 123
  • 2
  • 2
  • 12

1 Answers1

1

You can easily convert the array to the string using the Implode function. You can convert the array into string by using NULL value. Here attaching a snippet of working code:

<?php 
$csv =array_map('str_getcsv', file('abc.csv'));
print_r($csv); 
echo implode("",$csv[0]);
?>