Mark H Posted March 24, 2011 Share Posted March 24, 2011 Hi all,I'm putting together a simple sign-in system at present, and the following code (which I have borrowed from a tutorial) I don't fully understand. $page_mode = isset($POST['page_mode']) ? $POST['page_mode'] : ' '; I understand the first part, but I don't understand the ? $POST[page_mode] : ' ' ; I have looked again through the tutorials, but can't seem to find what the ? in the middle does?Thanks,Mark. Link to comment Share on other sites More sharing options...
Synook Posted March 24, 2011 Share Posted March 24, 2011 The ?...: sequence is the ternary operator - it goes condition ? true-statement : false-statement, so in this case it means: if (isset($POST['page_mode'])) { $page_mode = $POST['page_mode'];} else { $page_mode = ' ';} Link to comment Share on other sites More sharing options...
Mark H Posted March 24, 2011 Author Share Posted March 24, 2011 Thanks Synook..I knew what the result would be, but not how it worked.Thanks for the swift help. Link to comment Share on other sites More sharing options...
ShadowMage Posted March 24, 2011 Share Posted March 24, 2011 In case you're interested:http://www.php.net/manual/en/language.oper...parison.ternary Link to comment Share on other sites More sharing options...
jeffman Posted March 24, 2011 Share Posted March 24, 2011 Be aware that the ternary is not exclusive to PHP. Many C-style languages use it, including JavaScript, which you might find useful. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.