问题描述
如何更新代码以避免使用each()函数?
if (count($HTTP_POST_VARS)) {
while (list($key,$val) = each($HTTP_POST_VARS)) {
print "<input type=\"hidden\" name=\"$key\" value=\"$val\">\n";
}
}
我尝试了这种解决方案,但没有成功:
if (count($HTTP_POST_VARS)) {
foreach ($HTTP_POST_VARS as $key => $val) {
print "<input type=\"hidden\" name=\"$key\" value=\"$val\">\n";
}
}
解决方法
您可以使用$_POST
if (count($_POST)) {
foreach ($_POST as $key => $val) {
print "<input type=\"hidden\" name=\"$key\" value=\"$val\">\n";
}
}
有关更多信息,请参见https://www.php.net/manual/en/reserved.variables.post.php
, list($key,$val) = each($HTTP_POST_VARS)
更改为
function a_each(&$arr){
$key = key($arr);
if (!$key)
return false;
$val = current($arr);
next($arr);
return array($key,$val);
}
list($key,$val) = each($HTTP_POST_VARS);