How can the logic for displaying different animal types (e.g. cat, mouse, bull terrier) be optimized in PHP?

To optimize the logic for displaying different animal types in PHP, we can use a switch statement instead of multiple if-else conditions. This will make the code more readable and efficient, especially when dealing with a large number of animal types.

$animal = "cat";

switch($animal) {
    case "cat":
        echo "Meow";
        break;
    case "mouse":
        echo "Squeak";
        break;
    case "bull terrier":
        echo "Woof";
        break;
    default:
        echo "Unknown animal type";
}