Php收集到同一个数组中,属性属于同一个人

时间:2013-04-13 15:17:53

标签: php multidimensional-array

我有像这样的html元素:

<div id="show">
<p>1. <input name="name[]" size="25" type="text">
<input name="surname[]" size="25" type="text">
<input name="email[]" size="50" type="text"></p>

<p>2. <input name="name[]" size="25" type="text">
<input name="surname[]" size="25" type="text">
<input name="email[]" size="50" type="text"></p>

<p>3. <input name="name[]" size="25" type="text">
<input name="surname[]" size="25" type="text">
<input name="email[]" size="50" type="text"></p>

<p>4. <input name="name[]" size="25" type="text">
<input name="surname[]" size="25" type="text">
<input name="email[]" size="50" type="text"></p>

<p>5. <input name="name[]" size="25" type="text">
<input name="surname[]" size="25" type="text">
<input name="email[]" size="50" type="text"></p>
</div>

这是带有虚拟数据的输出屏幕。enter image description here 当我序列化div#show并发布它时,转储数据如下所示:

array (size=3)
  0 => 
    array (size=5)
      0 => string 'Hüsamettin' (length=11)
      1 => string 'Niyazi' (length=6)
      2 => string 'Abuzittin' (length=9)
      3 => string 'Haşmet' (length=7)
      4 => string 'Birben' (length=6)
  1 => 
    array (size=5)
      0 => string 'Karadayürümez' (length=15)
      1 => string 'Tuzyemez' (length=8)
      2 => string 'Yerebasmaz' (length=10)
      3 => string 'Haşmetligil' (length=12)
      4 => string 'Eksiktim' (length=8)
  2 => 
    array (size=5)
      0 => string 'husamettin@getmail.us' (length=21)
      1 => string 'tuzyemez@postmail.us' (length=20)
      2 => string 'abuzittin@setmail.us' (length=20)
      3 => string 'hasmetligil@mail.us' (length=19)
      4 => string 'birseneksiktim@mail.us' (length=22)

您会看到,第一个数组收集名称,第二个数组收集姓氏,第三个数组收集电子邮件地址。但我想像这样收集它们:

array (size=5)
  0 => 
    array (size=3)
      0 => string 'Hüsamettin' (length=11)
      1 => string 'Karadayürümez' (length=15)
      2 => string 'husamettin@getmail.us' (length=21)
  1 => 
    array (size=3)
      0 => string 'Niyazi' (length=6)
      1 => string 'Tuzyemez' (length=8)
      2 => string 'tuzyemez@postmail.us' (length=20)
  2 => 
    array (size=3)
      0 => string 'Abuzittin' (length=9)
      1 => string 'Yerebasmaz' (length=10)
      2 => string 'abuzittin@setmail.us' (length=20)
  3 => 
    array (size=3)
      0 => string 'Haşmet' (length=7)
      1 => string 'Haşmetligil' (length=12)
      2 => string 'hasmetligil@mail.us' (length=19)
  4 => 
    array (size=3)
      0 => string 'Birben' (length=6)
      1 => string 'Eksiktim' (length=8)
      2 => string 'birseneksiktim@mail.us' (length=22)

此数组类型收集人员的姓名,电子邮件地址,如上图所示。请问你能帮助我吗?如何创建一个从第一个HTML元素中收集某人姓名,电子邮件地址的数组? 亲切的问候。

1 个答案:

答案 0 :(得分:4)

$grouped = array_map(null, $_POST['name'], $_POST['surname'], $_POST['email']);