且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从PHP中的同名文本框中获取帖子

更新时间:2021-09-03 23:19:36

您必须命名文本框txt[],以便PHP为您创建一个数字索引数组:

You have to name your textboxes txt[] so PHP creates a numerically indexed array for you:

<?php
// $_POST['txt'][0] will be your first textbox
// $_POST['txt'][1] will be your second textbox
// etc.    

var_dump( $_POST['txt'] );
// or
foreach ( $_POST['txt'] as $key => $value )
{
  echo 'Textbox #'.htmlentities($key).' has this value: ';
  echo htmlentities($value);
}

?>

否则,最后一个文本框的值将覆盖所有其他值!

Otherwise the last textbox' value will overwrite all other values!

您还可以创建关联数组:

You could also create associative arrays:

<input type="text" name="txt[numberOne]" />
<input type="text" name="txt[numberTwo]" />
<!-- etc -->

但是然后您必须自己照顾名称,而不是让PHP来做.

But then you have to take care of the names yourself instead of letting PHP doing it.