How to keep value of selected value after form submission?



PHP Snippet 1:

<form action="index.php" method="POST">
    <select id="s" name="dtype" class="dropdown" required style="...">
        <option value="">Select Data Type</option>
        <option value="401" <?php if(isset($_POST['dtype']) && $_POST['dtype']=="401") {echo'selected';} ?>>Current</option>
        <option value="402" <?php if(isset($_POST['dtype']) && $_POST['dtype']=="402") {echo'selected';} ?>>Voltage</option>
        <option value="403" <?php if(isset($_POST['dtype']) && $_POST['dtype']=="403") {echo'selected';} ?>>kWh</option>
    </select>
</form>