dpdyh86002 2017-06-26 15:15
浏览 84
已采纳

显示数组中复选框的名称

I'm attempting to display the names of my checkboxes with the foreach statement below, but all I'm getting is "on" for each one checked. I've got the code for one of the checkboxes and was wondering if there is anything I can change in it to make this work.

if(!empty($_POST['OUSdrop'])){
    foreach($_POST['OUSdrop'] as $check){
        echo $check;
    }
}


<label class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect" for="UKSen">
    <input type="checkbox" id="UKSen" name="OUSdrop[]" class="mdl-checkbox__input">
    <span class="mdl-checkbox__label" value="UK">United Kingdom</span>
</label>
  • 写回答

3条回答 默认 最新

  • dsedug8644 2017-06-26 15:21
    关注

    why don't change it as

    <input type="checkbox" id="UKSen" name="OUSdrop[UK]" class="mdl-
    checkbox__input">
    

    so that you know which one you want to set?

    And also change the loop

    foreach($_POST['OUSdrop'] as $check => $value){
            echo $check.':'.$value;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助