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);
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments