mrherman Posted December 19, 2010 Share Posted December 19, 2010 Hello -- I'm trying to work through a very simple CMS that I found on the web (just for learning purposes). I need some help understanding this line: <table> <form method="POST" action="account.php?mode=save<?=( isset($_REQUEST['id']) ? "&id={$_REQUEST['id']}" : null )?> <? I understand the Method = "POST", but not the "action = " line. Thanks for any help. Link to comment https://forums.phpfreaks.com/topic/222107-not-understanding-a-line-of-code-from-a-simple-cms-program/ Share on other sites More sharing options...
quelle Posted December 19, 2010 Share Posted December 19, 2010 am i blind or this guy is starting/ending php code with <? ?> Link to comment https://forums.phpfreaks.com/topic/222107-not-understanding-a-line-of-code-from-a-simple-cms-program/#findComment-1149120 Share on other sites More sharing options...
Pikachu2000 Posted December 19, 2010 Share Posted December 19, 2010 The ?: is called the ternary operator. Basically a shorthand if/else conditional. Link to comment https://forums.phpfreaks.com/topic/222107-not-understanding-a-line-of-code-from-a-simple-cms-program/#findComment-1149123 Share on other sites More sharing options...
Anti-Moronic Posted December 19, 2010 Share Posted December 19, 2010 First of all <? ?> are short tags. Shouldn't be using them as not all installations have this enabled by default. Second ?: (see pikachu above) ..and: <?=( isset($_REQUEST['id']) ? "&id={$_REQUEST['id']}" : null )?> can be written as <?php echo ( isset($_REQUEST['id']) ? "&id={$_REQUEST['id']}" : null ); ?> or if(isset($_REQUEST['id']){ echo "&id={$_REQUEST['id']}"; }else{ echo null; } Hopefully that will help clarify the line for you. Note: echo null would not be done, you wouldn't use an else. Link to comment https://forums.phpfreaks.com/topic/222107-not-understanding-a-line-of-code-from-a-simple-cms-program/#findComment-1149125 Share on other sites More sharing options...
mrherman Posted December 19, 2010 Author Share Posted December 19, 2010 Yes, this clarifies the line. Thanks to all very much this evening! Link to comment https://forums.phpfreaks.com/topic/222107-not-understanding-a-line-of-code-from-a-simple-cms-program/#findComment-1149140 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.