提交后在复选框上显示值

时间:2014-05-04 16:00:47

标签: php html

我有一个像这样的php文件

    <form action='#' method='POST'>
    <p>
        <input type='checkbox' name='interest[]' value="music">music
        <input type='checkbox' name='interest[]' value="reading book">reading book
        <input type='checkbox' name='interest[]' value="coding">coding

    </p>
<input type='submit' name='send'><br/>
    </form>

我试图foreach循环输出所选的值。但是它总是输出“Array”;

<?php
foreach($_POST as $keys =>$values)
{
    echo $values."<br/>";
}
?>

1 个答案:

答案 0 :(得分:0)

<?php
if (isset($_POST))
{
    foreach($_POST as $keys1 =>$values1)
    {
       if (count($values1) > 0)
       {
         foreach($values1 as $keys2 =>$values2)
         {
           echo $values2."<br/>";
         }
       }
    }
}
?>