How to sort out a variable from a foreach loop ?

Discussion in 'PHP' started by luden, Apr 15, 2010.

  1. #1
    Sorry it was this code !:

    isset($_POST['n']))?$_POST['n']:null;

    I think it is like a conditon (if,then,else)?
    What exactly does it means ?
    Thanks

    Frank
     
    Last edited: Apr 15, 2010
    luden, Apr 15, 2010 IP
  2. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
    #2
    Quite simply, as it reads......

    If there is a form value named "submit" in the POST data then echo "test"
     
    lukeg32, Apr 15, 2010 IP
  3. aTo

    aTo Active Member

    Messages:
    473
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    78
    #3
    it means that <condition>?TRUE:FALSE;

    it is just like that...
    if(<condition>)
    {
    //true values here
    }
    else
    {
    //false values here
    }

    hope it helps :)
     
    aTo, Apr 15, 2010 IP
  4. David3

    David3 Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    The other posters answered your question, but now I have a question -- when would such code be useful? Because if $_POST['n'] is not set (not "isset"), then wouldn't it automatically be null? In other words, isn't it like saying if an orange is not in the basket, then it is not in the basket?
     
    David3, Apr 17, 2010 IP
  5. aTo

    aTo Active Member

    Messages:
    473
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    78
    #5
    the code is quite useless, it is because the isset() function checks null... cause, when u wanna use a ternary operator, chances are u need a catcher variable, $variable = (<condition>) ? TRUE : FALSE;

    just make sure ur program is very logical... :)
     
    aTo, Apr 17, 2010 IP