Jonathan Greenberg
asked on
How to phrase php if statement as ternary
I'm not even sure I'm saying this correctly, but I want to express the following php if statement as a ternary operator. I'd be grateful if someone would show me how.
Thanks!
if (!empty($_GET['invoice'])) {
$invoice = $_GET['invoice'];
}
else { $invoice = 1; }
I'm inclined to do this$invoice = !empty($_GET['invoice'] ? $_GET['invoice'] : 1;
But that appears to be wrong.Thanks!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you logu, Dave, Gary and Ray. I appreciate all the responses! It looks like the bottom line is, as Gary pointed out, I neglected to include a closing parenthesis.
And Ray, special thanks to you for pointing me to the php -l command line prompt! I can see that as being very useful.
Regards,
Jon
And Ray, special thanks to you for pointing me to the php -l command line prompt! I can see that as being very useful.
Regards,
Jon
$get_invoice = $_GET['invoice'];
$invoice = (!empty($get_invoice)) ? $get_invoice : 1;