How can PHP's typecasting affect the selection of dropdown list options?

When PHP typecasts variables, it can lead to unexpected behavior when comparing values. To ensure that the selected option in a dropdown list matches the expected value, it's important to explicitly cast variables to the correct type before comparing them.

<?php
// Example code to prevent issues with PHP typecasting in dropdown list selection

// Assume $selectedOption is the selected value from the dropdown list
$selectedOption = $_POST['dropdown'];

// Cast $selectedOption to the correct type before comparing
if ((int)$selectedOption === 1) {
    echo "Option 1 selected";
} elseif ((int)$selectedOption === 2) {
    echo "Option 2 selected";
} elseif ((int)$selectedOption === 3) {
    echo "Option 3 selected";
} else {
    echo "Invalid option selected";
}
?>