0
对不起,关于该标题,如果它很混乱,尽我所能描述我的问题。如何格式化属于组的输入名称
所以我有一些输入,在一个表单中,我想将它们组合在一起,因为它们是同一实体的一部分。
我知道使用括号,以便它们被放入一个数组(通过PHP),例如使用复选框时,但我的情况有点不同。
我有3个输入为person
,在形式上,可以有多个people
。
这是它会是什么样子如果我只有一个人的形式是什么:
<input type="text" name="first_name"/>
<input type="text" name="last_name"/>
<input type="text" name="email"/>
但是,我需要让多个people
,我想他们都在一个来通过阵列中的PHP,这样的:
// print_r($_POST['people']);
array(
[0] => array(
'first_name'=>'john'
'last_name' => 'smith'
'email'=>'[email protected]'
)
[1] => array(
'first_name'=>'john2'
'last_name' => 'smith2'
'email'=>'[email protected]'
)
)
我已经尝试(1):
<input type="text" name="people[][first_name]"/>
<input type="text" name="people[][last_name]"/>
<input type="text" name="people[][email]"/>
一个d我曾尝试(2):
<input type="text" name="people[first_name][]"/>
<input type="text" name="people[last_name][]"/>
<input type="text" name="people[email][]"/>
和我曾尝试(3):
<input type="text" name="people[][first_name][]"/>
<input type="text" name="people[][last_name][]"/>
<input type="text" name="people[][email][]"/>
以上都不在我所提到的进一步上面的结构来通过。
我如何让$_POST['people']
看起来像我上面显示的数组?
编辑:
这里是(1)生产:
Array
(
[0] => Array
(
[first_name] => john
)
[1] => Array
(
[last_name] => smith
)
[2] => Array
(
[email] => [email protected]
)
[3] => Array
(
[first_name] => john2
)
[4] => Array
(
[last_name] => smith2
)
[5] => Array
(
[email] => [email protected]
)
)
感谢。
什么是变1号的问题? –
@u_mulder我已经更新了我的问题,以显示变体1产生的东西('print_r'-ing'$ _POST ['people']') –