What are the PHP operators “?” and “:” called and what do they do?

前端 未结 10 1690

What are the ? and : operators in PHP?

For example:

(($request_type == \'SSL\') ? HTTPS_SERVER : HTTP_SERVER)
10条回答
  •  一向
    一向 (楼主)
    2020-11-22 05:18

    This is sometimes known as the ternary conditional operator. Ternary means that it has three arguments, as x ? y : z. Basically, it checks if x is true; if it is, then put y instead of this operation, otherwise z.

    $hello = $something ? "Yes, it's true" : "No, it's false";
    

提交回复
热议问题