"PHP 널 병합 연산자 ??"의 두 판 사이의 차이

잔글 (Jmnote님이 PHP 널 합체 연산자 문서를 PHP 널 병합 연산자 문서로 이동했습니다)
1번째 줄: 1번째 줄:
==개요==
==개요==
;PHP null coalescing operator
;PHP null coalescing operator
;PHP null 합체 연산자
;PHP 널 병합 연산자, PHP null 합체 연산자
;<code>??</code>
;<code>??</code>
* PHP 버전 7에 도입됨
* PHP 버전 7에 도입됨

2021년 7월 16일 (금) 10:37 판

1 개요

PHP null coalescing operator
PHP 널 병합 연산자, PHP null 합체 연산자
??
  • PHP 버전 7에 도입됨
$var1 = 'hello';
$var2 = null;
var_dump( $var1 ?? 'default' );
var_dump( $var2 ?? 'default' );
var_dump( $var3 ?? 'default' );
# string(5) "hello"
# string(7) "default"
# string(7) "default"
$prices = ['apple'=>300,'lemon'=>200];
var_dump( $prices['apple'] ?? 300 );
var_dump( $prices['banana'] ?? 100 );
var_dump( $prices['lemon'] ?? 100 );
# int(300)
# int(100)
# int(200)

2 같이 보기

3 참고

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}