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() に無効な引数が指定されました
ありがとう!