4

我有elements如下输入

        <form method="post" >
1       <input type="text" name="passname[name]" /> <br/> <br/>
2       <input type="text" name="passname[type]" /> <br/> <br/>
3       <input type="text" name="passname[age]" /> <br/> <br/>

1       <input type="text" name="passname[name]" /> <br/> <br/>
2       <input type="text" name="passname[type]" /> <br/> <br/>
3       <input type="text" name="passname[age]" /> <br/> <br/>

        <input type="submit" name="send" value="Submit" /> <br/>
    </form>

我想要所有的text boxas 数组php

像下面

Passenger Name : passname[name]
Passenger Type : passname[type]
Passenger Age : passname[age]

这可能与php

表格中使用的表格代码

<input type="text" name="passname[name][]" /> <br/> <br/>
<input type="text" name="passname[type][]" /> <br/> <br/>
<input type="text" name="passname[age][]" /> <br/> <br/>

<input type="text" name="passname[name][]" /> <br/> <br/>
<input type="text" name="passname[type][]" /> <br/> <br/>
<input type="text" name="passname[age][]" /> <br/> <br/>

当我提交表单时,我得到这种类型的数组值

    array
  'passname' => 
        array
          'name' => 
            array
              0 => string '1' (length=1)
              1 => string '1' (length=1)
          'type' => 
            array
              0 => string '2' (length=1)
              1 => string '2' (length=1)
          'age' => 
            array
              0 => string '3' (length=1)
              1 => string '3' (length=1)
      'send' => string 'Submit' (length=6)

我怎么能在每一个喜欢的打击中做到这一点

<?php
if(isset($_POST['aa']))
{
    $number = $_POST['1'];
    $text = $_POST['2'];
    foreach($number as $key=>$val)
    {
        echo $val."=".$text[$key]."<br />";
    }
}
?>
<formid="a"name="a"method="post">
<selectid="1[]"name="1[]">
<optionvalue="1">1</option>
<optionvalue="3">3</option>
<optionvalue="2">2</option>
</select>
<inputtype="text"value=""id="2[]"name="2[]"/>
<selectid="1[]"name="1[]">
<optionvalue="1">1</option>
<optionvalue="3">3</option>
<optionvalue="2">2</option>
</select>
<inputtype="text"value=""id="2[]"name="2[]"/>
<inputtype="submit"id="aa"name="aa"value="send now"/>
</form>
4

3 回答 3

7
<input type="text" name="passname[name][]" /> <br/> <br/>
<input type="text" name="passname[type][]" /> <br/> <br/>
<input type="text" name="passname[age][]" /> <br/> <br/>
于 2012-09-03T10:16:41.067 回答
6
<form method="post" >
       <input type="text" name="passname[name][]" /> <br/> <br/>
       <input type="text" name="passname[type][]" /> <br/> <br/>
       <input type="text" name="passname[age][]" /> <br/> <br/>

       <input type="text" name="passname[name][]" /> <br/> <br/>
      <input type="text" name="passname[type][]" /> <br/> <br/>
       <input type="text" name="passname[age][]" /> <br/> <br/>

        <input type="submit" name="send" value="Submit" /> <br/>
    </form>

<?php
$_POST['passname']['name'];
$_POST['passname']['type'];
$_POST['passname']['age'];
?>
于 2012-09-03T10:16:12.887 回答
0

如果你想让乘客分开,你应该像这样构建你的表单:

<form method="post" >
  <input type="text" name="passname[0][name]" /> <br/> <br/>
  <input type="text" name="passname[0][type]" /> <br/> <br/>
  <input type="text" name="passname[0][age]" /> <br/> <br/>

  <input type="text" name="passname[1][name]" /> <br/> <br/>
  <input type="text" name="passname[1][type]" /> <br/> <br/>
  <input type="text" name="passname[1][age]" /> <br/> <br/>

  <input type="submit" name="send" value="Submit" /> <br/>
</form>

然后,一旦提交,您的$_POST数组将如下所示:

$_POST == array(
  0 => array(
    'name' => 'XXX',
    'type' => 'XXX',
    'age' => 'XXX',
  ),
  1 => array(
    'name' => 'XXX',
    'type' => 'XXX',
    'age' => 'XXX',
  ),
  'send' => 'Submit',
);

其中XXX表示用户输入数据。

于 2012-09-03T10:20:33.953 回答