我有一个简单的脚本,如下所示:
$row_to_show = 2;
$handle = fopen('myfile.csv', 'r');
if ($handle !== false) {
$row_count = 0;
while($csv_line = fgetcsv($handle)) {
$row_count++;
if ($row_count == $row_to_show) {
$latestResults = ($csv_line);
echo json_encode($latestResults);
}
}
}
它抓取 CSV 文件中的第二行。然后将其编码为 json 格式并显示如下:
["2013 年 4 月 20 日","46","8","34","38","44","42","14","4","MERLIN"]
但是,我想做的是:
"Date":20-Apr-2013,"ball1":46,"ball2":8,"ball3":34,"ball4":38,"ball5":44"ball6":42,"bonusball":14,"set":4,"machine":MERLIN
我如何实现这一目标?提前致谢