dongti8535 2013-04-13 15:17
浏览 21
已采纳

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

I have html elements like this:

<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>

And this is the output screen with dummy datas.enter image description here When I serialize div#show and post it, dumping datas are like below:

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)

You see, first array collects names, second array collects surnames and third array collects email addresses. But I want to collect them like this:

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)

This array type collects person's name, surname and email address like image above. Please could you help me, how do I create an array which collects someone's name, surname and email address from the first HTML elements? Kind regards.

  • 写回答

1条回答 默认 最新

  • doufei3561 2013-04-13 15:25
    关注
    $grouped = array_map(null, $_POST['name'], $_POST['surname'], $_POST['email']);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 速帮,学校需要在外上班没空
  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改
  • ¥15 Windows 系统cmd后提示“加载用户设置时遇到错误”
  • ¥50 vue router 动态路由问题
  • ¥15 关于#.net#的问题:End Function
  • ¥15 无法import pycausal
  • ¥15 VS2022创建MVC framework提示:预安装的程序包具有对缺少的注册表值的引用
  • ¥15 weditor无法连接模拟器Local server not started, start with?
  • ¥20 6-3 String类定义