drxv39706 2012-01-24 13:47
浏览 79
已采纳

输入类型复选框中的值数组?

<form action="next.php" method="post">
<table>
    <tr>
      <td>Paul</td>
      <td>Attuck</td>
      <td>paulattuck@yahoo.com</td>
      <td><input type="checkbox" name="list[]" value="paulattuck@yahoo.com" /></td>
    </tr>
    <tr>
      <td>James</td>
      <td>Bond</td>
      <td>jamesbond@yahoo.com</td>
      <td><input type="checkbox" name="list[]" value="jamesbond@yahoo.com" /></td>
    </tr>
    <tr>
      <td>Name</td>
      <td>Last</td>
      <td>lastname@yahoo.com</td>
      <td><input type="checkbox" name="list[]" value="lastname@yahoo.com" /></td>
    </tr>
</table>
    <input type="submit" name="submit" value="submit" />
</form>

and if i checked all checkbox and send form to next.php i can:

print_r($_POST['tags']);
// output
Array
(
    [0] => paulattuck@yahoo.com
    [1] => jamesbond@yahoo.com
    [2] => lastname@yahoo.com
)

How can i make:

Array
    (
        [0] => array ([0] => Paul
                      [1] => Attuck
                      [2] => paulattuck@yahoo.com)
        [1] => array ([0] => James
                      [1] => Bond
                      [2] => jamesbond@yahoo.com)
        [2] => array ([0] => Last
                      [1] => Name
                      [2] => lastname@yahoo.com)
    )

? I try use serialize but this make " - dont can use this in html form.

  • 写回答

3条回答 默认 最新

  • duanpin5168 2012-01-24 13:53
    关注

    If you make sure there is one character forbidden in the name fields (I use | here), you can do

    <tr>
          <td>Paul</td>
          <td>Attuck</td>
          <td>paulattuck@yahoo.com</td>
          <td><input type="checkbox" name="list[]" value="Paul|Attuck|paulattuck@yahoo.com" /></td>
    </tr>
    

    And will get

    print_r($_POST['tags']);
    // output
    Array
    (
        [0] => Paul|Attuck|paulattuck@yahoo.com
        [1] => James|Bond|jamesbond@yahoo.com
        [2] => Last|Name|lastname@yahoo.com
    )
    

    Which you can transform by

    $names=array();
    foreach ($_POST['tags']) as $tag)
      $names[]=explode('|',$tag,3);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。