shortened php if else block

后端 未结 2 1609
小鲜肉
小鲜肉 2020-12-22 06:12

what is the shorted if else block for this. I seen it somewhere before but cant remember it.

if (isset($_POST[\'value\')){
 $value = $_POST[\'value\'];
} els         


        
2条回答
  •  不知归路
    2020-12-22 06:48

    Are you referring to using the $_REQUEST global array instead of checking both $_POST and $_GET? If so, it should be:

    if(isset($_REQUEST['value']))
    {
        $value = $_REQUEST['value'];
    }else
        $value = '';
    

    Or the ternary form:

    $value = isset($_REQUEST['value']) ? $_REQUEST['value'] : '';
    

提交回复
热议问题