php read csv to array
$lines =file('CSV Address.csv');
foreach($lines as $data)
{
list($name[],$address[],$status[])
= explode(',',$data);
}
php read csv to array
$lines =file('CSV Address.csv');
foreach($lines as $data)
{
list($name[],$address[],$status[])
= explode(',',$data);
}
php array to csv string
To convert an array into a CSV file we can use fputcsv() function. The fputcsv() function is used to format a line as CSV (comma separated values) file and writes it to an open file. The file which has to be read and the fields are sent as parameters to the fputcsv() function and it returns the length of the written string on success or FALSE on failure.
Syntax :
fputcsv( file, fields, separator, enclosure, escape )
Example:
<?php
// Create an array of elements
$list = array(
['Name', 'age', 'Gender'],
['Bob', 20, 'Male'],
['John', 25, 'Male'],
['Jessica', 30, 'Female']
);
// Open a file in write mode ('w')
$fp = fopen('persons.csv', 'w');
// Loop through file pointer and a line
foreach ($list as $fields) {
fputcsv($fp, $fields);
}
fclose($fp);
?>
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us