19 lines
397 B
PHP
19 lines
397 B
PHP
<?php
|
|
|
|
namespace App\Stubs;
|
|
|
|
function getCSV(string $filename, $names = []): \Generator
|
|
{
|
|
if (false !== ($handle = fopen($filename, "r"))) {
|
|
while (false !== ($data = fgetcsv($handle))) {
|
|
if (empty($names)) {
|
|
$names = $data;
|
|
continue;
|
|
}
|
|
|
|
yield array_combine($names, $data);
|
|
}
|
|
fclose($handle);
|
|
}
|
|
}
|