What does this mean?

Discussion in 'PHP' started by Darkhodge, Mar 19, 2007.

  1. #1
    Hi,


    I was just looking at someone elses code and came across this:

    $request_uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : "";
    Code (markup):
    What do the bit after the '?' and ':' mean?


    Thanks,

    Hodge :)
     
    Darkhodge, Mar 19, 2007 IP
  2. maonnie

    maonnie Member

    Messages:
    71
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    43
    #2
    Its a ternary operator. The example above will set $request_uri to the value of $_SERVER['REQUEST_URI'] if $_SERVER['REQUEST_URI'] was set, if it wasn't $request_uri will be set to an empty string.

    condition ? true-value : false-value;
     
    maonnie, Mar 19, 2007 IP
  3. Darkhodge

    Darkhodge Well-Known Member

    Messages:
    2,111
    Likes Received:
    76
    Best Answers:
    1
    Trophy Points:
    185
    #3
    Ah right - thank now I understand :)
     
    Darkhodge, Mar 19, 2007 IP