我收到了以下while循环错误:
解析错误:语法错误,意想不到的T_ENCAPSED_AND_WHITESPACE,期望T_STRING
$index=1;
while ($index <= 100):
fwrite($outfile, $_POST[''"variable_" . $index'']);
fwrite($outfile, "'r");
$index = $index + 1;
endwhile;
fclose($outfile);
?>
包括variable_1, variable_2, variable_3没有得到语法错误的正确方法是什么?
谢谢。
$x = "variable_$index";
fwrite($outfile, $_POST[$x]);
我也会考虑在这里使用for循环。
// Assuming you open $outfile somewhere prior to this
for ( $i = 1; $i <= 100; $i++ ) {
$x = "variable_$i";
fwrite($outfile, $_POST[$x]);
fwrite($outfile, "'r");
}
fclose($outfile);
看起来你把引号弄混了——你不需要''部分:
$_POST["variable_" . $index]
single
和double
引号有误
fwrite($outfile, $_POST["'variable_" . $index."'"]);
fwrite($outfile, implode("'r", array_values($_POST)));