greens85 Posted May 21, 2009 Share Posted May 21, 2009 Hi all, I currently have an IF statement like so: <?php if ($a4[AA] == 'Yes') { ?><font color="#990000"><?echo "Some Text"?><font> <? } else { echo ""; } ?> <?php if ($a4[AB] == 'Yes') { ?><font color="#990000"><?echo "Another line of text"?><font> <? } else { echo ""; } ?> This works perfectly fine, although its a bit long winded, is there any way i can incorporate this all into one if statement, and have the text seperated by a comma. There are 8 different fields that could be equal to 'Yes'. Thanks Link to comment https://forums.phpfreaks.com/topic/159071-multiple-if-statements/ Share on other sites More sharing options...
Daniel0 Posted May 21, 2009 Share Posted May 21, 2009 Okay? Thanks for letting us know Link to comment https://forums.phpfreaks.com/topic/159071-multiple-if-statements/#findComment-838873 Share on other sites More sharing options...
JonnoTheDev Posted May 21, 2009 Share Posted May 21, 2009 LOL Link to comment https://forums.phpfreaks.com/topic/159071-multiple-if-statements/#findComment-838874 Share on other sites More sharing options...
greens85 Posted May 21, 2009 Author Share Posted May 21, 2009 lol, good wit guys. I pressed post by accident. I have now modified it! Link to comment https://forums.phpfreaks.com/topic/159071-multiple-if-statements/#findComment-838877 Share on other sites More sharing options...
ToonMariner Posted May 21, 2009 Share Posted May 21, 2009 <?php $textarr = array('AA'=>'Some Text', 'AB'=>'Other text', ..... 'AH'=>'Last Text'); foreach($a4 as $key => $val) { if(strcasecmp($val,'yes'~) == 0) { ?> <font color="#990000"><?php echo $textarr[$key]; ?><font> <?php } } ?> the textarr could be populated from a database but I get the impression that this could be refactored maybe in favour of a switch statement.... Link to comment https://forums.phpfreaks.com/topic/159071-multiple-if-statements/#findComment-838884 Share on other sites More sharing options...
greens85 Posted May 21, 2009 Author Share Posted May 21, 2009 Exactly what i was looking for mate, much appreciated. Link to comment https://forums.phpfreaks.com/topic/159071-multiple-if-statements/#findComment-838896 Share on other sites More sharing options...
greens85 Posted May 21, 2009 Author Share Posted May 21, 2009 Actually, the comma isnt showing in between the text. Have i done something wrong? Link to comment https://forums.phpfreaks.com/topic/159071-multiple-if-statements/#findComment-838900 Share on other sites More sharing options...
jsschmitt Posted May 21, 2009 Share Posted May 21, 2009 You just need to throw the comma in the quotes... <?php $textarr = array('AA'=>'Some Text,', 'AB'=>'Other text,', ..... 'AH'=>'Last Text'); foreach($a4 as $key => $val) { if(strcasecmp($val,'yes'~) == 0) { ?> <font color="#990000"><?php echo $textarr[$key]; ?><font> <?php } } ?> Link to comment https://forums.phpfreaks.com/topic/159071-multiple-if-statements/#findComment-839076 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.