Overview of PHP shorthand

后端 未结 9 1221
小鲜肉
小鲜肉 2020-12-12 15:32

I\'ve been programming in PHP for years now, but I\'ve never learned how to use any shorthand. I come across it from time to time in code and have a hard time reading it, s

9条回答
  •  醉梦人生
    2020-12-12 15:44

    Nobody mentioned ??!

    // Example usage for: Null Coalesce Operator
    $action = $_POST['action'] ?? 'default';
    
    // The above is identical to this if/else statement
    if (isset($_POST['action'])) {
        $action = $_POST['action'];
    } else {
        $action = 'default';
    }
    

提交回复
热议问题