What is the meaning of the '?', '()', and ':' symbols in PHP?

后端 未结 4 1087
一整个雨季
一整个雨季 2021-01-14 02:17

I\'ve finally remembered what to ask. I never really got what : and ? do when a variable is being defined like this:

$ip = ($_SERVER[\'HTTP_X_FORWARDED_FOR\'         


        
4条回答
  •  -上瘾入骨i
    2021-01-14 03:18

    "?:" (or ternary) operator
    

    The expression (expr1) ? (expr2) : (expr3) evaluates to expr2 if expr1 evaluates to TRUE, and expr3 if expr1 evaluates to FALSE

    See this example:

    
    

提交回复
热议问题