我的 PHP 脚本需要很长时间才能在文件中回显数据。似乎我在某些循环上出错了,而且处理时间太长。有人可以看看我的代码,让我知道我哪里出错了吗?我的任务是遍历 JSON 数据数组并在 XML 标记中回显数据。我的 json 数组如下所示 [["GENERIC SALES PRICE", ""],["REGION", "SALE PRICE"],["AMERICA", "260,000"],["ASIA","340,000"],。 。ETC]
$fp = fopen("data_save2.json", "r");
$inp=file_get_contents("data_save2.json");
fclose($fp);
$inp=json_decode($inp);
$inp_info=$inp;
$start_row=0;
$start_col=0;
for($i=0; $i <= $inp_info; $i++) {
for($j=0; $j <= $inp_info; $j++) {
if ($inp_info[$i][$j]=='GENERIC SALES PRICE') {
$start_row=$i+1;
$start_col=$j;
}
$row_index=$start_row;
$rows_of_data=0;
while($inp_info[$row_index][$start_col]!=''){
$rows_of_data = $rows_of_data+1;
$row_index = $row_index+1;}
}
}
$dir = "C:/../data/GenericSalePrice.xml";
$fp = fopen($dir, 'w');
fwrite($fp,'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>');
fwrite($fp,"\n");
fwrite($fp,'<generic-sales-price xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">');
fwrite($fp,"\n");
for($j=0; $j<=$rows_of_data; $j++){
fwrite($fp,"\t<sale-price>\n");
$region = $inp_info[$start_row+$j][$start_col];
fwrite($fp, "\t\t<region>");
fwrite($fp,"$region");
fwrite($fp, "</region>\n");
$price =$inp_info[$start_row+$j][$start_col+1];
fwrite($fp, "\t\t<price>");
fwrite($fp, "$price");
fwrite($fp, "</price>\n");
fwrite($fp, "\t</sale-price>\n");
}
fwrite($fp, "</generic-sales-price>");
fclose($fp);
请帮我解决这个问题,在此先感谢