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 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' : ''); 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. 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. Link to comment https://forums.phpfreaks.com/topic/264503-concatenate-several-if-results/#findComment-1355575 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.