• Discussion
  • How to set selected properties in multiple checkboxes with foreach loop in PHP?

How to set selected properties in multiple checkboxes with foreach loop in PHP?

    Do you have an example of your form with the checkboxes? Your question is a bit vague.

      Are you talking about something like this?

      $foo = array(
        'something' => 25,
        'another_thing' => 'fubar'
      );
      foreach($foo as $name => $value) {
        echo "<div><label>".ucfirst(str_replace('_', ' ', $name)).": <input type='checkbox' name='$name' value='$value'></label></div>\n";
      }
      
        Write a Reply...