mjahkoh Posted June 20, 2012 Share Posted June 20, 2012 Hi Folks. Why cant this work. Its necessary in some instances. How can i do it in 1 line. echo 'one'. if ($x=$y) 'add 2' . if ($a=$b) 'add 4'; Regards Quote Link to comment https://forums.phpfreaks.com/topic/264503-concatenate-several-if-results/ Share on other sites More sharing options...
ManiacDan Posted June 20, 2012 Share Posted June 20, 2012 You need to use the ternary operator echo 'one' . ($x=$y ? 'add 2' : '') . ($a=$b ? 'add 4' : ''); Quote Link to comment https://forums.phpfreaks.com/topic/264503-concatenate-several-if-results/#findComment-1355482 Share on other sites More sharing options...
Mahngiel Posted June 20, 2012 Share Posted June 20, 2012 echo 'one' . ($x=$y ? 'add 2' : '') . ($a=$b ? 'add 4' : ''); Just noting here, but this is assignment and not comparison. Quote Link to comment https://forums.phpfreaks.com/topic/264503-concatenate-several-if-results/#findComment-1355567 Share on other sites More sharing options...
ManiacDan Posted June 20, 2012 Share Posted June 20, 2012 OP already marked this solution as solved, so he's in for a surprise when he tries this code in a real environment. Good eye. Quote Link to comment https://forums.phpfreaks.com/topic/264503-concatenate-several-if-results/#findComment-1355575 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.