note 127779 added to function.fgetcsv

From: Date: Thu, 20 Oct 2022 07:55:34 +0000
Subject: note 127779 added to function.fgetcsv
Groups: php.notes 
Request: Send a blank email to php-notes+get-219729@lists.php.net to get a copy of this message
Shorter solution to the handling proposed by jack dot peterson at gmail dot com. Not sure if more efficient, but I guess nowadays you all have at least 1GB RAM :)). Let me know @email. He wrote: „If you receive data in the following format: Time,Dataset1,Dataset2, timestamp1,item 1 for dataset 1,item1 for dataset2 timestamp2,item 2 for dataset 1,item2 for dataset2 the following code will output a series of arrays grouped by column with the resulting format: array ( [column 1 title] => array ( [timestamp1] => item1 for dataset1 [timestamp2] => item2 for dataset1 ) [column 2 title] => array ( [timestamp1] => item1 for dataset2 [timestamp2] => item2 for dataset2 ) )” $filename = "mybeautifulcsv.csv"; $collected = array_map('str_getcsv', file($filename)); $total = count($collected[0]); for($i=0; $i<$total; $i++): $formated[$collected[0][$i]] = array_column($collected, $i, 0); endfor; array_shift($formated); //var_dump($formated); ---- Server IP: 45.112.84.4 Probable Submitter: 45.91.159.161 (proxied: 82.77.78.65) ---- Manual Page -- https://php.net/manual/en/function.fgetcsv.php Edit -- https://main.php.net/note/edit/127779 Del: integrated -- https://main.php.net/note/delete/127779/integrated Del: useless -- https://main.php.net/note/delete/127779/useless Del: bad code -- https://main.php.net/note/delete/127779/bad+code Del: spam -- https://main.php.net/note/delete/127779/spam Del: non-english -- https://main.php.net/note/delete/127779/non-english Del: in docs -- https://main.php.net/note/delete/127779/in+docs Del: other reasons-- https://main.php.net/note/delete/127779 Reject -- https://main.php.net/note/reject/127779 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#219729) next »