note 129904 added to function.str-getcsv
| From: | nicolasbonnici@gmail.com | Date: | Sat, 07 Dec 2024 23:31:13 +0000 |
| Subject: | note 129904 added to function.str-getcsv | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-221707@lists.php.net to get a copy of this message | ||
Better way to get an associative key value array output.
$output = [];
$lines = array_values(explode(PHP_EOL, $your_csv_string));
$headers = str_getcsv(array_shift($lines));
foreach ($lines as $line) {
$parsedLine = str_getcsv($line);
if (count($headers) !== count($parsedLine)) {
continue;
}
$output[] = array_combine($headers, $parsedLine);
}
var_dump($output);
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.137 (proxied: 2a01:cb00:11e4:f200:638b:ec65:8077:f0bc)
----
Manual Page -- https://php.net/manual/en/function.str-getcsv.php
Edit -- https://main.php.net/note/edit/129904
Del: integrated -- https://main.php.net/note/delete/129904/integrated
Del: useless -- https://main.php.net/note/delete/129904/useless
Del: bad code -- https://main.php.net/note/delete/129904/bad+code
Del: spam -- https://main.php.net/note/delete/129904/spam
Del: non-english -- https://main.php.net/note/delete/129904/non-english
Del: in docs -- https://main.php.net/note/delete/129904/in+docs
Del: other reasons-- https://main.php.net/note/delete/129904
Reject -- https://main.php.net/note/reject/129904
Search -- https://main.php.net/manage/user-notes.php