ngreenwood6 Posted October 3, 2009 Share Posted October 3, 2009 I am trying to do an inline if statement. I havent done it in awhile so I forget the correct syntax but if I wanted to put this code on one line how would I do it? if(isset($_GET['test'])) { $message = $_GET['test']; } else { $message = ''; } Any help is appreciated. I know it is a ? and a : but cant remember it exactly lol Link to comment https://forums.phpfreaks.com/topic/176348-if-statement/ Share on other sites More sharing options...
Alex Posted October 3, 2009 Share Posted October 3, 2009 The format is: $var = (expression) ? 'what to make it if the expression is true' : 'what to make it if it is false'; so: $message = (isset($_GET['test'])) ? $_GET['test'] : NULL; Link to comment https://forums.phpfreaks.com/topic/176348-if-statement/#findComment-929459 Share on other sites More sharing options...
lipun4u Posted October 3, 2009 Share Posted October 3, 2009 $message = (isset($_GET['test']) ? $_GET['test'] : ''); Link to comment https://forums.phpfreaks.com/topic/176348-if-statement/#findComment-929461 Share on other sites More sharing options...
ngreenwood6 Posted October 3, 2009 Author Share Posted October 3, 2009 Thanks a million guys. Needed a refresher lol Link to comment https://forums.phpfreaks.com/topic/176348-if-statement/#findComment-929463 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.