dongshuo2752 2016-04-20 12:36
浏览 47
已采纳

如何使用php在复选框中显示数组值?

I am using the following code

$val= $module[$i]['subModule'];
$val1=$module[$i]['submoduleId'];
$valArr['name'] = explode(",", $val);
$valArr1['id']= explode(",", $val1);
$result=array_merge($valArr,$valArr1);
foreach($result as $name)
{
    if(!empty($name))
    {
        echo "<input type='checkbox' name='type[]' value='".$name['id']."'>".$name['name']." ";
    }
}

It show the undefined index error.

I print the $result variable I got the following output:

Array ( [name] => Array (
                  [0] => group
                  [1] => checkin
                  [2] => personalinfo 
                 ) 
         [id] => Array ( 
                  [0] => 3 
                  [1] => 2
                  [2] => 1 
                 )
      )
  • 写回答

1条回答 默认 最新

  • doormen2014 2016-04-20 12:50
    关注

    Try This Code:

    foreach($result['name'] as $key => $name){
        echo "<input type='checkbox' name='type[]' value='".$result['id'][$key]."'>".$name." ";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?