扩大
缩小

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

  

posted @ 2017-11-06 09:07  悟空聊架构  阅读(1435)  评论(0编辑  收藏  举报
Copyright ©2019 悟空聊架构