How can the code be modified to exclude letters that do not appear in the dataset from being displayed?

To exclude letters that do not appear in the dataset from being displayed, we can modify the code to check if each letter in the input string exists in the dataset before displaying it. If the letter is not found in the dataset, we skip displaying it. This way, only letters that are present in the dataset will be shown.

$dataset = "abcde";
$input = "aabbccddeeff";

for ($i = 0; $i < strlen($input); $i++) {
    $letter = $input[$i];
    if (strpos($dataset, $letter) !== false) {
        echo $letter;
    }
}