Search
 
SCRIPT & CODE EXAMPLE
 

PHP

How to create an array from a CSV file using PHP

public function csvToArray($filename = '', $delimiter = ','){
  if(!file_exists($filename) || !is_readable($filename))
  	return false;
  $header = null;
  $data = array();
  if(($handle = fopen($filename, 'r')) !== false){
  	while(($row = fgetcsv($handle, 1000, $delimiter)) !== false){
  		if(!$header)
  			$header = $row;
  		else
  			$data[] = array_combine($header, $row);
  	}
  	fclose($handle);
  }
  return $data;
}
    
    
Comment

php read csv file into array

$file = fopen('myCSVFile.csv', 'r');
while (($line = fgetcsv($file)) !== FALSE) {
  //$line is an array of the csv elements
  print_r($line);
}
fclose($file);
Comment

php read csv to array

$lines =file('CSV Address.csv');

foreach($lines as $data)
{
list($name[],$address[],$status[])
= explode(',',$data);
}
Comment

PREVIOUS NEXT
Code Example
Php :: delete image s3 laravel 
Php :: random word using a wordlist php 
Php :: how get role of user in laravel spatie 
Php :: php month single digit 
Php :: composer create project version 
Php :: php get current time and date 
Php :: laravel request integer 
Php :: format money with commas in php 
Php :: strval in php 
Php :: laravel loop counter 
Php :: wordpress require file from plugins folder 
Php :: how to add data to an object in php 
Php :: how to use php echo data in javascript 
Php :: convert multi-dimensional array into a single array in laravel 
Php :: pass parameter to view laravel 
Php :: how to check if user is logged in wordpress 
Php :: laravel model limit 
Php :: laravel count by date 
Php :: php check undefined offset 
Php :: php capitalize first letter 
Php :: php error reporting 
Php :: codeigniter table list 
Php :: json_decode object to array 
Php :: woo set_stock_quantity 
Php :: laravel image ratio validation 
Php :: how to zip a folder using php 
Php :: --prefer-dist what is use in laravel 
Php :: php remove duplicates from multidimensional array 
Php :: delete multiple row in laravel 
Php :: json to array php 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =