How can you set a default value for select boxes in PHP?
To set a default value for select boxes in PHP, you can use an if statement to check if the option value matches the default value, and then add the 'selected' attribute to that option. This will ensure that the specified option is selected by default when the select box is rendered.
<select name="example_select">
<option value="option1" <?php if($default_value == 'option1') echo 'selected'; ?>>Option 1</option>
<option value="option2" <?php if($default_value == 'option2') echo 'selected'; ?>>Option 2</option>
<option value="option3" <?php if($default_value == 'option3') echo 'selected'; ?>>Option 3</option>
</select>