How to Convert JSON file into CSV in PHP ?

如何將JSON格式輸出成CSV的檔案呢??

<?php

// Student JSON data
$jsondata =
'[
{"student":"大毛","age":22,"subject":"java"},
{"student":"中毛","age":21,"subject":"java"},
{"student":"小毛","age":22,"subject":"dbms"},
{"student":"無毛","age":22,"subject":"sql"}]';

// Decode json data and convert it
// into an associative array
$jsonans = json_decode($jsondata, true);

// CSV file name => test.csv
$csv = 'test.csv';

// File pointer in writable mode
$file_pointer = fopen($csv, 'w');

// Traverse through the associative
// array using for each loop
foreach($jsonans as $i){
	
	// Write the data to the CSV file
	fputcsv($file_pointer, $i);
}

// Close the file pointer.
fclose($file_pointer);

?>

如果有什麼問題,也可以在下方留言處與我們分享,感謝您!!

手刀試用=>蝦皮對帳王

手刀試用=>康捷雲端ERP

相關文章

👉 進出貨一覽表 簡單王 操作步驟詳解

👉 簡單王-進出貨匯入上傳工具 操作步驟詳解

👉 蝦皮對帳王-蝦皮對帳結果一覽表-為什麼要對帳?無對應???

👉 蝦皮對帳王-對帳原理分析-有訂單,有撥款だいじょうぶ(大丈夫);有訂單,沒撥款 歐NO~~~~~!!!

[蝦皮服務] 訂單完成後什麼時候能夠收到款項呢?

期待您的留言

Comments

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *