perky416 Posted May 18, 2011 Share Posted May 18, 2011 Hi everyone, I know im being really picky here, but im trying to optimize my code, and i was wondering if there is any way i can shorten the following: if ($submit) {echo $name;} else {echo $row['dbname'];} I know it fairly short already however im using it as the value of a html text box. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/236766-is-it-possible-to-shorten-this/ Share on other sites More sharing options...
wildteen88 Posted May 18, 2011 Share Posted May 18, 2011 You can use a ternary operator echo (($submit) ? $name : $row['dnname']); Quote Link to comment https://forums.phpfreaks.com/topic/236766-is-it-possible-to-shorten-this/#findComment-1217100 Share on other sites More sharing options...
perky416 Posted May 18, 2011 Author Share Posted May 18, 2011 Hi Wildteen88, Iv just googled ternary operators. Thats a really handy and simple way to if statements. Nice one Quote Link to comment https://forums.phpfreaks.com/topic/236766-is-it-possible-to-shorten-this/#findComment-1217104 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.