Function to display image

Sarah

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?

Funk Forty Niner

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.

edited at
0

Comments

0 comments
Login to comment

Related

Refused to display image in Thymeleaf

How to display image in message part in wp_mail function?

Building a PHP function to display an image gallery from a multidimensional array

Django: How display a different image according to my function in views.py

How to display an image on an iFrame?

display is not a function

Is there a function to display an image in tkinter (that is any file type) and display it as a specific x-y position on the canvas

I am trying to write a function to display the histogram of an image

Create function to display an image or placeholder image for a single product

Write text on image as display as image

Display datepicker in image location

onload image, call function to display alert

How to create a radio button with on and off function to display an image?

Display image on top of gif

display image in different resolution

How to display the image from ajax success function?

Display image one at a time?

Codeigniter:Update Image and Display

VueJS - Function to display image

Display function of EBImage package do not show interactive image in shinyapps.io

Display image caption on the bottom of the image

Flask: display newly generated image on webpage while continuing with function?

Display image button using function

How can I get my function to display over an image (and retain the image)?

How can I get my function to display text over an image?

Is there any function or method to display clusters of mage after k means image segmentation?

React upload and display image

Conditionally display an image in a cell

Passing image to function as a char array in C++ and display with SFML

TOP Ranking

HotTag

Archive