Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implode error for PHP

Tags:

php

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?

like image 962
Doug Molineux Avatar asked Sep 17 '25 14:09

Doug Molineux


1 Answers

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.

like image 123
kb. Avatar answered Sep 20 '25 03:09

kb.