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