$filePath = 'data/users.csv';
$lines = array_map('str_getcsv', file($filePath));
$result = array();
$headers = null;
if (count($lines) > 0) {
    $headers = $lines[0];
}
for ($i = 1; $i < count($lines); $i++) {
    $obj = mb_convert_encoding($lines[$i], "UTF-8", "GBK"); //防止乱码
    $result[] = array_combine($headers, $obj);
}

$json = json_encode($result,JSON_PRETTY_PRINT); // JSON_PRETTY_PRINT 美化