PHP if statement. Display and image if true -


i'm accessing api returning value of array. want image displayed based on result. example if div contains "above average" display image called aboveaverage.png.

echo $cinfo['crimes']['2013-03']['anti-social-behaviour']['crime_level']; 

this results "above average" how can display particular image correspond this?

something ->

if div "crime_level" = above average then: display aboveaverage.png 

i'm pretty new php, sorry i'm noob.

use case selecting switch

switch ($cinfo['crimes']['2013-03']['anti-social-behaviour']['crime_level']) {               case "above average":                 $image = "aboveaverage.png";             break;             case "below average":                 $image = "belowaverage.png";             break;             default:                 $image = "unknown.png";             };  echo "<img src=\"$image\" />"; 

doing way allows remove logic display setting variable $image you're not having update 20 different potential image tags. allows cater many different cases of string without ending lost in if else hell


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -