라이브러리
[PHP] get_debug_type - 디버깅에 적합한 방식으로 변수의 유형 이름을 가져옵니다.
PHP의 get_debug_type() 함수
PHP 7.0 버전부터 소개된 `get_debug_type()` 함수는 변수의 데이터 타입을 확인하는 데 사용됩니다. 이 함수는 변수의 실제 타입을 반환합니다.
# 사용법
`get_debug_type()` 함수는 변수의 데이터 타입을 반환하는 데 사용됩니다. 이 함수는 변수의 타입을 문자열로 반환합니다.
# 예제
#hostingforum.kr
php
// 변수 선언
$a = 10;
$b = 'hello';
$c = true;
$d = array(1, 2, 3);
$e = null;
$f = new stdClass();
// get_debug_type() 함수 사용
echo get_debug_type($a) . "
"; // integer
echo get_debug_type($b) . "
"; // string
echo get_debug_type($c) . "
"; // boolean
echo get_debug_type($d) . "
"; // array
echo get_debug_type($e) . "
"; // null
echo get_debug_type($f) . "
"; // object
# 결과
#hostingforum.kr
integer
string
boolean
array
null
object
# 예시 2: 타입 확인
#hostingforum.kr
php
// 변수 선언
$a = 10;
$b = 'hello';
// 타입 확인
if (get_debug_type($a) === 'integer') {
echo "변수 $a는 정수입니다.
";
} else {
echo "변수 $a는 정수가 아닙니다.
";
}
if (get_debug_type($b) === 'string') {
echo "변수 $b는 문자열입니다.
";
} else {
echo "변수 $b는 문자열이 아닙니다.
";
}
# 결과
#hostingforum.kr
변수 10는 정수입니다.
변수 hello는 문자열입니다.
# 예시 3: 타입 변환
#hostingforum.kr
php
// 변수 선언
$a = 10;
// 타입 변환
$b = (string) $a;
// 타입 확인
echo get_debug_type($a) . "
"; // integer
echo get_debug_type($b) . "
"; // string
# 결과
#hostingforum.kr
integer
string
결론
`get_debug_type()` 함수는 변수의 데이터 타입을 확인하는 데 사용됩니다. 이 함수는 변수의 실제 타입을 문자열로 반환합니다. 이 함수를 사용하여 변수의 타입을 확인하고, 타입 변환을 수행할 수 있습니다.
-
- 나우호스팅 @pcs8404
-
호스팅포럼 화이팅!
댓글목록
등록된 댓글이 없습니다.