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 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']); 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 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
Archived
This topic is now archived and is closed to further replies.