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

前端 未结 10 1688

What are the ? and : operators in PHP?

For example:

(($request_type == \'SSL\') ? HTTPS_SERVER : HTTP_SERVER)
10条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-22 05:25

    That is a one line if statement:

    condition ? true : false
    

    Translated to an ordinary if statement in your case, that would be:

    if($request_type == 'SSL') HTTPS_SERVER;
    else HTTP_SERVER;
    

提交回复
热议问题