multiple checkboxes - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6) +--- Forum: CodeIgniter 2.x (https://forum.codeigniter.com/forumdisplay.php?fid=18) +--- Thread: multiple checkboxes (/showthread.php?tid=65659) |
multiple checkboxes - prtk418 - 07-07-2016 PHP Code: <div class="container"> RE: multiple checkboxes - mwhitney - 07-08-2016 The problem you are describing is probably here: PHP Code: if ($db_key = array_search($val, $services)) If $val is the first entry in $services, the key is probably 0, so your if() statement evaluates to false and moves on to the else clause. The manual entry for array_search() includes a warning about this behavior: http://php.net/manual/en/function.array-search.php#refsect1-function.array-search-returnvalues So, you could rewrite this as: PHP Code: $db_key = array_search($val, $services); or you could do something like this: PHP Code: $db_key = array_search($val, $services); or you could use the form helper's form_checkbox() or set_checkbox() functions. https://codeigniter.com/userguide2/helpers/form_helper.html |