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? Quote 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 Quote 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?";}?> Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.