PHP 的内爆错误
我有一个表单,其中有三个复选框,如下所示:
<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">
然后我提取($_POST),并有此代码,
$comServices = implode(",", $services);
但出现错误:
警告:implode() [function.implode]:传入的参数无效..
有谁知道为什么我会收到此错误?
I have a form where I've got three checkboxes like this:
<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">
and then I extract($_POST), and have this code
$comServices = implode(",", $services);
but I get an error:
Warning: implode() [function.implode]: Invalid arguments passed in ..
does anyone know why Im getting this error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果没有选择任何复选框,$services 将是未定义的而不是空数组。
您可以执行
$comServices = implode(",", (array)$services);
来防止它。If none of your checkboxes was selected $services would be undefined rather than an empty array.
You can do
$comServices = implode(",", (array)$services);
to prevent it.当没有选中复选框时,
$services
将为空(如null
中的空,而不是“空数组”中的空)。您必须测试 $services 是否实际上是一个数组:
$services
will be empty when there is no check box checked (empty as innull
, not as in "an empty array").You'd have to test whether $services actually is an array:
通常,这意味着您的变量不是数组...您可以使用 is_array() 函数检查它...
Usually, that means your variable is not an array... You can check for it with the is_array() function...