从多个复选框中获取POST数据?

Lia*_*iam 16 php post

我试图使用PHP创建一个表单,我似乎无法找到我需要的教程,所以我想在这里问.

我的页面上有一个多重复选框选项...

 <li>
    <label>What service are you enquiring about?</label>
    <input type="checkbox" value="Static guarding" name="service">Static guarding<br>
    <input type="checkbox" value="Mobile Patrols" name="service">Mobile Patrols<br>
    <input type="checkbox" value="Alarm response escorting" name="service">Alarm response escorting<br>
    <input type="checkbox" value="Alarm response/ Keyholding" name="service">Alarm response/ Keyholding<br>
    <input type="checkbox" value="Other" name="service">Other<input type="hidden" value="Other" name="service"></span>
  </li>
Run Code Online (Sandbox Code Playgroud)

但我不确定如何使用POST方法收集所有复选框值?

如果我使用

$service = $_POST['service'];
Run Code Online (Sandbox Code Playgroud)

我只得到'其他'返回

Lek*_*eyn 45

将字段命名为service[]而不是service,然后您将能够以数组的形式访问它.之后,您可以将常规函数应用于数组: