PHP, Shorthand, If..Else using Ternary Operators

前端 未结 2 1984
孤街浪徒
孤街浪徒 2021-01-20 18:37

Is there a oneliner for this? A nice Ternary OP?

$F_NAME = $_SESSION[\'USR\'][\'F_NAME\'];
if(isset($_POST[\'F_NAME\'])) {$F_NAME = $_POST[\'F_NAME\'];}
         


        
2条回答
  •  -上瘾入骨i
    2021-01-20 19:09

    Its supposed to be:

    (conditions) ? true : false
       satisfies <--^      ^----> did not satisfy
    

    So this equates into:

    $F_NAME = isset($_POST['F_NAME']) ? $_POST['F_NAME'] : $_SESSION['USR']['F_NAME'];
    

提交回复
热议问题