RE: [PHP] ? : where in the manual?
same from : header("Location: ".(empty($SESSION["wantsurl"]) ? $CFG->wwwroot : $SESSION["wantsurl"])); Exit; or, if not readable enough then: if(empty($SESSION["wantsurl"])) { $goto = $CFG->wwwroot; } else { $goto = $SESSION["wantsurl"]; } header("Location: $goto"); Exit; // or die; (condition) ? 'result if true' : 'if false'; is exactly same thing as: if(condition) { 'result if true'; } else { 'if false'; } the only difference: it can be only one line (one semilon ';') on any of the two results and can be only ONE evaluation (no 'elseif') and must have an 'else'; I'll tell you also a few reasons to use this syntax: 1. less lines for PHP to compile. 2. saves you the headache when there are lot's of conditions to do inside the strings or function returns; 3. less useless variables to declare. Good question though, where is this documented? I knew it from other languages... but never came accross it on PHP docs except the code samples.. Sincerely, Maxim Maletsky Founder, Chief Developer PHPBeginner.com (Where PHP Begins) [EMAIL PROTECTED] www.phpbeginner.com -Original Message- From: Rehuel Lobato de Mesquita [mailto:[EMAIL PROTECTED]] Sent: Wednesday, July 11, 2001 1:16 AM To: [EMAIL PROTECTED] Subject: [PHP] ? : where in the manual? Heya guys, I am trying to find information in the manual to explain these lines: $goto = empty($SESSION["wantsurl"]) ? $CFG->wwwroot : $SESSION["wantsurl"]; header("Location: $goto"); die; Can anyone tell me where to look??? Thanx -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] ? : where in the manual?
These are called (well, one name for it), is ternary operator. It's not PHP specific and a search on google will find some results. Regarding PHP, brief discussion (with examples) can be found at the following locations : http://www.php.net/manual/language.expressions.php http://www.php.net/manual/language.operators.comparison.php I don't think it's recommended to use it for multiple lines, looks kinda screwy. Although, each to their own. Regards, Philip On Tue, 10 Jul 2001, Rehuel Lobato de Mesquita wrote: > Heya guys, > > I am trying to find information in the manual to explain these lines: > > $goto = empty($SESSION["wantsurl"]) ? $CFG->wwwroot : > $SESSION["wantsurl"]; > header("Location: $goto"); > die; > > Can anyone tell me where to look??? > > Thanx > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] ? : where in the manual?
www.php.net/empty www.php.net/header the x ? Y : z; form is a quick n easy structure that works like if/else do a search for classes and objects for the $CFG->wwwroot part jack -Original Message- From: Rehuel Lobato de Mesquita [mailto:[EMAIL PROTECTED]] Sent: Tuesday, July 10, 2001 12:16 PM To: [EMAIL PROTECTED] Subject: [PHP] ? : where in the manual? Heya guys, I am trying to find information in the manual to explain these lines: $goto = empty($SESSION["wantsurl"]) ? $CFG->wwwroot : $SESSION["wantsurl"]; header("Location: $goto"); die; Can anyone tell me where to look??? Thanx -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] ? : where in the manual?
Heya guys, I am trying to find information in the manual to explain these lines: $goto = empty($SESSION["wantsurl"]) ? $CFG->wwwroot : $SESSION["wantsurl"]; header("Location: $goto"); die; Can anyone tell me where to look??? Thanx -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]