Any more concise way to set default values?

后端 未结 5 1461
轮回少年
轮回少年 2020-12-19 12:11

Since PHP 5.3, it is possible to leave out the middle part of the ternary operator. Expression expr1 ?: expr3 returns expr1 if expr1 evaluates to TRUE, an

5条回答
  •  长情又很酷
    2020-12-19 12:42

    Just asked this and was pointed here. So in case you use a key of an array, this might be an improvement

    function isset_get($array, $key, $default = null) {
        return isset($array[$key]) ? $array[$key] : $default;
    }
    

提交回复
热议问题