PHP簡(jiǎn)單獲取多個(gè)checkbox值的方法

字號(hào):


    本文實(shí)例講述了PHP簡(jiǎn)單獲取多個(gè)checkbox值的方法。分享給大家供大家參考,具體如下:
    HTML頁(yè)面:
    <html>
     <head>
     </head>
     <body>
     <form name="myform" enctype="multipart/form-data" action="index2.php" method="post">
      興趣愛(ài)好:<input type="checkbox" name="hobby[]" value="閱讀"/>閱讀
      <input type="checkbox" name="hobby[]" value="籃球"/>籃球
      <input type="checkbox" name="hobby[]" value="旅游"/>旅游
      <br>
    文件上傳:<input name="myfile" type="file">
      <input type="submit" value="提交" />
     </form>
     </body>
    </html>
    PHP頁(yè)面:
    $result = "";
    foreach( $_POST['hobby'] as $i)
    {
     echo '<br>';
     $result .= $i;
    }
    echo $result;
    希望本文所述對(duì)大家php程序設(shè)計(jì)有所幫助。