What best practices should be followed when using loops and conditional statements to populate and select data in a SelectBox in PHP?

When populating a SelectBox in PHP using loops and conditional statements, it is important to properly structure the code to ensure efficiency and readability. Best practices include using a loop to iterate over an array of data, using conditional statements to filter or manipulate the data before populating the SelectBox, and properly formatting the output to ensure it is valid HTML.

<select name="selectBox">
    <?php
    $data = array("Option 1", "Option 2", "Option 3", "Option 4");
    
    foreach($data as $option) {
        if($option != "Option 3") {
            echo "<option value='$option'>$option</option>";
        }
    }
    ?>
</select>