How can conditional statements like if-else or switch-case be utilized to update input fields in PHP?

To update input fields based on certain conditions in PHP, you can use conditional statements like if-else or switch-case. These statements allow you to check specific conditions and update the input fields accordingly. For example, you can check if a certain value is selected in a dropdown menu and update other input fields based on that selection.

<?php
$selectedValue = $_POST['dropdown'];

if($selectedValue == 'option1') {
    $input1 = 'Value for option 1';
    $input2 = 'Another value for option 1';
} elseif($selectedValue == 'option2') {
    $input1 = 'Value for option 2';
    $input2 = 'Another value for option 2';
} else {
    $input1 = '';
    $input2 = '';
}
?>

<input type="text" name="input1" value="<?php echo $input1; ?>">
<input type="text" name="input2" value="<?php echo $input2; ?>">