rv20 Posted May 22, 2009 Share Posted May 22, 2009 $page = (isset($_GET['page'])) ? $_GET['page'] : "main"; Really just the isset the "?" and generally what it is doing Quote Link to comment https://forums.phpfreaks.com/topic/159281-solved-coudl-someone-explain-this-line-of-code/ Share on other sites More sharing options...
dennismonsewicz Posted May 22, 2009 Share Posted May 22, 2009 its short hand for an if/else statement. if page is set then get page else do whatever "main" is Quote Link to comment https://forums.phpfreaks.com/topic/159281-solved-coudl-someone-explain-this-line-of-code/#findComment-840051 Share on other sites More sharing options...
Philip Posted May 22, 2009 Share Posted May 22, 2009 To add onto what Dennis said, it's called a ternary operation. http://us3.php.net/ternary#language.operators.comparison.ternary And isset checks to see if the variable has been set (is set) Quote Link to comment https://forums.phpfreaks.com/topic/159281-solved-coudl-someone-explain-this-line-of-code/#findComment-840057 Share on other sites More sharing options...
Axeia Posted May 22, 2009 Share Posted May 22, 2009 If you need more information, look up Ternary Operator Quote Link to comment https://forums.phpfreaks.com/topic/159281-solved-coudl-someone-explain-this-line-of-code/#findComment-840059 Share on other sites More sharing options...
rv20 Posted May 22, 2009 Author Share Posted May 22, 2009 Ok so in longhand, if (isset($_GET['page']) == "")){ $_GET['page']; }else{ $page = "main"; } that doesn't make sense if $_GET['page'] is not set then $_GET['page'] Quote Link to comment https://forums.phpfreaks.com/topic/159281-solved-coudl-someone-explain-this-line-of-code/#findComment-840060 Share on other sites More sharing options...
Axeia Posted May 22, 2009 Share Posted May 22, 2009 The "long" code would be: $page = (isset($_GET['page'])) ? $_GET['page'] : "main"; $page = ''; if( isset( $_GET['page'] ) ) { $page = $_GET['page'] } else { $page = 'main'; } Quote Link to comment https://forums.phpfreaks.com/topic/159281-solved-coudl-someone-explain-this-line-of-code/#findComment-840069 Share on other sites More sharing options...
rv20 Posted May 22, 2009 Author Share Posted May 22, 2009 The "long" code would be: $page = (isset($_GET['page'])) ? $_GET['page'] : "main"; $page = ''; if( isset( $_GET['page'] ) ) { $page = $_GET['page'] } else { $page = 'main'; } Ahhh, I get it all now, thanks. Quote Link to comment https://forums.phpfreaks.com/topic/159281-solved-coudl-someone-explain-this-line-of-code/#findComment-840080 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.