DEV Community

웹학교
웹학교

Posted on

2 2

php ?? 연산자 (Null coalescing operator)

PHP 7.0.x부터 도입된 ?? 연산자를 소개합니다.

기존의 삼항 연산자에 대한 더 편리한 방법이라고 해야 하나요?

사용방법

$username = $_GET['user'] ?? '홍길동';
Enter fullscreen mode Exit fullscreen mode

이것은 기존의

$username = isset($_GET['user']) ? $_GET['user'] : '홍길동';
Enter fullscreen mode Exit fullscreen mode

과 같습니다.


더 확장하여 다음과 같이 사용할 수도 있습니다.

$username = $_GET['user'] ?? $_POST['user'] ?? '홍길동';
Enter fullscreen mode Exit fullscreen mode

출처

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay