PHP Velho Oeste 2024

gettype

(PHP 4, PHP 5, PHP 7)

gettype변수의 자료형을 얻습니다

설명

string gettype ( mixed $var )

PHP 변수 var의 자료형을 반환합니다.

Warning

gettype()을 어떤 자료형인지 시험하기 위해 사용하지 마십시오. 반환 문자열은 앞으로 나올 버전에서 바뀔 수 있습니다. 또한, 문자열 비교를 수행하기 때문에 느립니다.

대신, is_* 함수를 사용하십시오.

인수

var

자료형을 확인할 변수

반환값

반환 문자열의 가능한 값은:

예제

Example #1 gettype() 예제

<?php

$data 
= array(11.NULL, new stdClass'foo');

foreach (
$data as $value) {
    echo 
gettype($value), "\n";
}

?>

위 예제의 출력 예시:

integer
double
NULL
object
string

참고

  • settype() - 변수의 자료형을 설정
  • is_array() - 변수가 배열인지 확인
  • is_bool() - 변수가 논리형인지 확인
  • is_float() - 변수의 자료형이 소수인지 확인합니다
  • is_int() - 변수의 자료형이 정수인지 확인합니다
  • is_null() - 변수가 NULL인지 확인합니다
  • is_numeric() - 변수가 수나 수 문자열인지 확인합니다
  • is_object() - 변수가 객체인지 확인합니다
  • is_resource() - 변수가 자원인지 확인
  • is_scalar() - 변수가 스칼라인지 확인
  • is_string() - 변수의 자료형이 문자열인지 확인합니다
  • function_exists() - Return TRUE if the given function has been defined
  • method_exists() - 클래스 메쏘드가 존재하는지 확인

add a note add a note

User Contributed Notes 2 notes

up
5
mohammad dot alavi1990 at gmail dot com
10 months ago
Be careful comparing ReflectionParameter::getType() and gettype() as they will not return the same results for a given type.

string - string // OK
int - integer // Type mismatch
bool - boolean // Type mismatch
array - array // OK
up
-46
Anonymous
2 years ago
Same as for "boolean" below, happens with integers. gettype() return "integer" yet proper type hint is "int".

If your project is PHP8+ then you should consider using get_debug_type() instead which seems to return proper types that match used for type hints.
To Top