mardi 26 janvier 2016

PHP display images if $value = $string?

I need to know if there's a quickest and efficient way to display one or more images if $value == $string

For example: I have an cell which only contains 3 single string: 'r o g', if user put ro it will output <img src="red.gif"> and <img src="orange.gif"> So it could be random if user insert gr then it will display <img src="green.gif"> and <img src="red.gif">

Right now I can only think something like...

<?php $red = "<img src="red.gif">"; $yellow = "<img src="yellow.gif">"; if( $cell1 == $red ){ echo $red;} if( $cell1 == $red && $yellow ){ echo $yellow.$red;} etc...?>

This method might works but has to provide too many possibility and I believe there's a shorter and efficient to do that, but I haven't got any idea because still I'm learning PHP

Aucun commentaire:

Enregistrer un commentaire