PHP的内爆错误

Dou*_*eux 2 php implode

我有一个表单,我有三个这样的复选框:

    <td>Wireless <input type="checkbox" name="services[]" value="wireless" /></td>
      </tr>
  <tr>
    <td>Cellular <input type="checkbox" name="services[]" value="cellular" /></td>
  </tr>
  <tr>
    <td>Security <input type="checkbox" name="services[]" value="Security" /></td>
<input type="submit" name="submit">
Run Code Online (Sandbox Code Playgroud)

然后我解压缩($ _ POST),并拥有此代码

$comServices = implode(",", $services);
Run Code Online (Sandbox Code Playgroud)

但是我收到一个错误:

警告:implode()[function.implode]:传入的参数无效..

有谁知道为什么我得到这个错误?

kb.*_*kb. 14

如果没有选中任何复选框,则$ services将是未定义的,而不是空数组.

你可以做到$comServices = implode(",", (array)$services);防止它.