What are the ? and : operators in PHP?
For example:
(($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is the conditional operator.
means “if
$xis true, then use$y; otherwise use$z“.It also has a short form.
means “if
$xis true, then use$x; otherwise use$z“.People will tell you that
?:is “the ternary operator”. This is wrong.?:is a ternary operator, which means that it has three operands. People wind up thinking its name is “the ternary operator” because it’s often the only ternary operator a given language has.