显示图像的功能

I have a Php function and I want it to display a photo...

<?php
function getImg ($src)
{
    switch ($src)
    {
        case "Sunny":
            echo "<img src='fakepath/sunny.png'>";
            break;
        case "Sad":
            echo "<img src='fakepath/sad.png'>";
            break;
        case "Smile":
            echo "<img src='fakepath/smile.png'>";
            break;
default: echo "nothing"; break;
    }
}

$style = "Sad";
getImg($style);

After getImg($style), it does not echo anything.

What's wrong?

You need to use $src when calling the function, and not $style

<?php
function getImg ($src)
{
    switch ($src)
    {
        case "Sunny":
            echo "<img src='fakepath/sunny.png'>";
            break;
        case "Sad":
            echo "<img src='fakepath/sad.png'>";
            break;
        case "Smile":
            echo "<img src='fakepath/smile.png'>";
            break;
    }
}

$src = "Sad";
getImg($src);

Working fine after adding a default clause

function getImg ($src)
{
    switch ($src)
    {
        case "Sunny":
            echo "<img src='fakepath/sunny.png'>";
            break;
        case "Sad":
            echo "<img src='fakepath/sad.png'>";
            break;
        case "Smile":
            echo "<img src='fakepath/smile.png'>";
            break;
        default :
            break;
    }
}

$style = "Sad";
getImg($style);