PHP csv文件内容转成数组/Json

$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 = $lines[$i];
    $result[] = array_combine($headers, $obj);//转成数组
}

$json =  json_encode($result, JSON_PRETTY_PRINT);//转成JSON

  

原文地址:https://www.cnblogs.com/jackson0714/p/7791595.html