我在 HTML 端有这段代码:
<form action="testx.php" method="post">
<input type="hidden" name="block-1" value="001"/>
<input type="hidden" name="block-2" value="012"/>
<input type="hidden" name="block-3" value="002"/>
<input type="hidden" name="block-4" value="005"/>
<input type="hidden" name="block-5" value="008"/>
<input type="hidden" name="title" value="title goes here"/>
<input type="hidden" name="code" value="018439128484"/>
<input type="submit" value="Finish!" class="submit-btn" />
</form>
我在 PHP 端有这个 Foreach 循环:
<?php
$i=0;
foreach($_POST as $name => $value)
{
echo $i . " - " . $name . ": " . $value . "<br>";
$i++;
}
?>
不幸的是,该 Foreach 循环进行所有输入...如何使该循环仅进行名称为“block-X”的输入?
我试着像这样尝试,但失败了:
$i=0;
$x = 'block-'.$i+1;
foreach($_POST[$x] as $name => $value)
它说:警告:为 foreach() 提供的参数无效
谢谢!