PHP Version
4+
$number = 10;
$string = 'Hello, world!';
$array = [1, 2, 3];
$object = new stdClass();

echo gettype($number); // 'integer'
echo gettype($string); // 'string'
echo gettype($array); // 'array'
echo gettype($object); // 'object'
gettype(mixed $value): string
$var1 = true;
$var2 = false;

$type1 = gettype($var1); // $type1 will contain 'boolean'
$type2 = gettype($var2); // $type2 will contain 'boolean'

// Mainly used in conditional statements and logical operations
if ($var1) {
    echo '$var1 is true.';
} else {
    echo '$var1 is false.';
}

if ($var2) {
    echo '$var2 is true.';
} else {
    echo '$var2 is false.';
}
$var2 = false;

// Use is_bool() to check if the variable is a boolean
if (is_bool($var1)) {
    echo '$var1 is a boolean.';
} else {
    echo '$var1 is not a boolean.';
}

if (is_bool($var2)) {
    echo '$var2 is a boolean.';
} else {
    echo '$var2 is not a boolean.';
}
$num1 = 10;
$num2 = -10;
$num3 = 0;

echo gettype($num1); // 'integer'
echo gettype($num2); // 'integer'
echo gettype($num3); // 'integer'
$num1 = 10;
$num2 = -10;
$num3 = 0;

echo is_int($num1); // true
echo is_int($num2); // true
echo is_int($num3); // true
$num1 = 10.5;
$num2 = -10.5;
$num3 = 0.0;

echo gettype($num1); // 'double'
echo gettype($num2); // 'double'
echo gettype($num3); // 'double'
$num1 = 10.5;
$num2 = -10.5;
$num3 = 0.0;

echo is_float($num1); // true
echo is_float($num2); // true
echo is_float($num3); // true
$str1 = 'Hello, world!';
$str2 = 'Welcome! Nice to meet you!';
$str3 = '';

echo gettype($str1); // 'string'
echo gettype($str2); // 'string'
echo gettype($str3); // 'string'
$str1 = 'Hello, world!';
$str2 = 'Welcome! Nice to meet you!';
$str3 = '';

echo is_string($str1); // true
echo is_string($str2); // true
echo is_string($str3); // true
$arr1 = [1, 2, 3];
$arr2 = ['Hello', 'world'];
$arr3 = [];

$arr4 = [
    'name' => 'John Doe',
    'age' => 30
];

echo gettype($arr1); // 'array'
echo gettype($arr2); // 'array'
echo gettype($arr3); // 'array'
echo gettype($arr4); // 'array'
$arr1 = [1, 2, 3];
$arr2 = ['Hello', 'world'];
$arr3 = [];

$arr4 = [
    'name' => 'John Doe',
    'age' => 30
];

echo is_array($arr1); // true
echo is_array($arr2); // true
echo is_array($arr3); // true
echo is_array($arr4); // true
class MyClass {
    public $name = 'John Doe';
    public $age = 30;
}

$obj1 = new MyClass();
$obj2 = clone $obj1;

echo gettype($obj1); // 'object'
echo gettype($obj2); // 'object'
class MyClass {
    public $name = 'John Doe';
    public $age = 30;
}

$obj1 = new MyClass();
$obj2 = clone $obj1;

echo is_object($obj1); // true
echo is_object($obj2); // true
// Open a file
$fp = fopen('test.txt', 'w');

echo gettype($fp); // 'resource'
// Open a file
$fp = fopen('test.txt', 'w');

echo is_resource($fp); // true
// Open a file
$fp = fopen('test.txt', 'w');

// Close the file handle
fclose($fp);

echo gettype($fp); // 'resource (closed)'
// Open a file
$fp = fopen('test.txt', 'w');

// Close the file handle
fclose($fp);

if (gettype($fp) == 'resource (closed)') {
    echo "The file pointer is closed."; // Output
} else {
    echo "The file pointer is still open.";
}
$a = null;
$b;

echo gettype($a); // 'NULL'
echo gettype($b); // 'NULL'
$a = null;
$b;

echo is_null($a); // true
echo is_null($b); // true