forumnz Posted December 30, 2007 Share Posted December 30, 2007 Can this be done? For example have: <?php echo "Example Text... My name is" . if ($name == bob) echo "Charlie" . ". Blah Blah?" ?> Can that be done? What is an alternative? Link to comment https://forums.phpfreaks.com/topic/83685-solved-if-statements-within-echo/ Share on other sites More sharing options...
hitman6003 Posted December 30, 2007 Share Posted December 30, 2007 use a ternary statement: <?php echo "Example Text... My name is" . ($name == "bob" ? "Charlie" : "") . ". Blah Blah?" ?> www.php.net/expressions Link to comment https://forums.phpfreaks.com/topic/83685-solved-if-statements-within-echo/#findComment-425780 Share on other sites More sharing options...
redarrow Posted December 30, 2007 Share Posted December 30, 2007 <?php echo "Example Text... My name is"; if ($name == bob){ echo "Charlie";}else{ echo " Blah Blah?";}?> Link to comment https://forums.phpfreaks.com/topic/83685-solved-if-statements-within-echo/#findComment-425783 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.