![点击查看原图 11.png](https://www.wlphp.com/content/uploadfile/202309/59b21693536594.png)
![点击查看原图 22.png](https://www.wlphp.com/content/uploadfile/202309/75c11693536600.png)
![点击查看原图 33.png](https://www.wlphp.com/content/uploadfile/202309/9c861693536605.png)
sanji.txt
public function index()
{
$filename = './test/sanji.txt'; // 替换为实际文件路径
// 读取文件内容
$jsonString = file_get_contents($filename);
// 解析 JSON 数据为数组
$dataArray = json_decode($jsonString, true);
// 确保解析成功
if ($dataArray === null) {
die('无法解析 JSON 数据');
}
//print_r($dataArray);
$good_arr = array();
foreach ($dataArray as $k => $v) {
$fenlei_name = $v["lei_id"];
//再来一层foreach
foreach ($v as $k1 => $v1) {
//如果是数组则回怼
if (is_array($v1)) {
$v1["fenlei"] = $fenlei_name;
$good_arr[] = $v1;
}
}
}
print_r($good_arr);
die;
create_xls($good_arr, "商品表");
die;
}