Search
 
SCRIPT & CODE EXAMPLE
 

PHP

csv to array in 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

column of csv to array php

$csv = array_map("str_getcsv", file("data.csv", "r")); 
$header = array_shift($csv); 
// Seperate the header from data

$col = array_search("Value", $header); 
 foreach ($csv as $row) {      
 $array[] = $row[$col]; 
}
Comment

csv to array php

$csv = array_map('str_getcsv', file('data.csv'));
Comment

PREVIOUS NEXT
Code Example
Php :: laravel composer update 
Php :: force delete soft delete laravel 
Php :: laravel clear page cache 
Php :: php read csv to array 
Php :: multiple middleware laravel 
Php :: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known 
Php :: php creazione numero random 
Php :: php weekdays 
Php :: how to change date formate in php 
Php :: php declare strict_types 
Php :: convert byte to megabyte php 
Php :: Deleting an element from an array in PHP 
Php :: require_once php 
Php :: flutter network image svg 
Php :: merge two query results in laravel 
Php :: php check if any of multiple values in array 
Php :: clear array php 
Php :: lcomposer symfony/filesystem 
Php :: skip add to cart for woocommerce 
Php :: php constant array 
Php :: php curl_exec get response json 
Php :: laravel get auth user id 
Php :: laravel fire event 
Php :: nested resources laravel 
Php :: download file php 
Php :: PHP not working centos 8 
Php :: ajax get request in laravel 
Php :: create project laravel 
Php :: clear laravel.log 
Php :: foreach reverse laravel 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =