"PHP isset()"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
5번째 줄: 5번째 줄:
* 선언된 적이 없으면 false
* 선언된 적이 없으면 false


<source lang='php' run once>
<syntaxhighlight lang='php' run once>
$a = 'hello';
$a = 'hello';
var_dump( isset( $a ) );
var_dump( isset( $a ) );
var_dump( isset( $b ) );
var_dump( isset( $b ) );
</source>
</syntaxhighlight>


{{소스헤더|unset()하면 false}}
{{소스헤더|unset()하면 false}}
<source lang='php' run>
<syntaxhighlight lang='php' run>
$a = 'hello';
$a = 'hello';
unset( $a );
unset( $a );
var_dump( isset( $a ) ); # bool(false)
var_dump( isset( $a ) ); # bool(false)
</source>
</syntaxhighlight>


{{소스헤더|여러 개 동시 확인 (하나라도 없으면 false)}}
{{소스헤더|여러 개 동시 확인 (하나라도 없으면 false)}}
<source lang='php' run>
<syntaxhighlight lang='php' run>
$b = 1;
$b = 1;
var_dump( isset( $b, $c ) ); # bool(false)
var_dump( isset( $b, $c ) ); # bool(false)
$c = 2;
$c = 2;
var_dump( isset( $b, $c ) ); # bool(true)
var_dump( isset( $b, $c ) ); # bool(true)
</source>
</syntaxhighlight>


{{소스헤더|배열 키 없으면 false}}
{{소스헤더|배열 키 없으면 false}}
<source lang='php' run>
<syntaxhighlight lang='php' run>
$arr = ['a'=>'hello'];
$arr = ['a'=>'hello'];
var_dump( isset($arr['a']) ); # bool(true)
var_dump( isset($arr['a']) ); # bool(true)
var_dump( isset($arr['b']) ); # bool(false)
var_dump( isset($arr['b']) ); # bool(false)
</source>
</syntaxhighlight>


==같이 보기==
==같이 보기==

2020년 11월 2일 (월) 02:34 판

1 개요

PHP isset()
  • 값이 설정되어 있고 NULL이 아닌지 판단하는 PHP 함수
  • NULL이 아닌 값이 설정되어 있으면 true
  • 선언된 적이 없으면 false
$a = 'hello';
var_dump( isset( $a ) );
var_dump( isset( $b ) );
unset()하면 false
$a = 'hello';
unset( $a );
var_dump( isset( $a ) ); # bool(false)
여러 개 동시 확인 (하나라도 없으면 false)
$b = 1;
var_dump( isset( $b, $c ) ); # bool(false)
$c = 2;
var_dump( isset( $b, $c ) ); # bool(true)
배열 키 없으면 false
$arr = ['a'=>'hello'];
var_dump( isset($arr['a']) ); # bool(true)
var_dump( isset($arr['b']) ); # bool(false)

2 같이 보기

3 참고

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