duandang2123 2012-02-02 19:00
浏览 22
已采纳

处理一个表单中的42个复选框

I have 42 checkboxes in my form as im programming a page where the user is choosing their interests.

By naming all the checkboxes "interest", is there any way of making an array of values?

Example:

<input  type="checkbox" name="interest" value="34" />
<input  type="checkbox" name="interest" value="19" />

//values in array
$interestArray[0] = 34;
$interestArray[1] = 19;
  • 写回答

3条回答 默认 最新

  • doulang1945 2012-02-02 19:02
    关注

    You're looking for this?

    <form method="POST" action="">
    <input  type="checkbox" name="interest[]" value="34" />
    <input  type="checkbox" name="interest[]" value="19" />
    <input  type="checkbox" name="interest[]" value="56" />
    
    //values in array
    $_POST['interest'][0] = 34;
    $_POST['interest'][1] = 19;
    $_POST['interest'][2] = 56;
    

    Specifying an arrays key is optional in HTML. If you do not specify the keys, the array gets filled in the order the elements appear in the form.

    From PHP manual: How do I create arrays in a HTML ?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度