PHP gettype() Function Last Updated : 13 Sep, 2024 Comments Improve Suggest changes Like Article Like Report The PHP gettype() function returns the type of a variable as a string. It identifies the variable's data type, such as string, integer, array, boolean, etc., allowing developers to check and handle different data types dynamically.Syntax:string gettype ( $var )Parameter: This function accepts a single parameter $var. It is the name of the variable which is needed to be checked for the type of variable.Return Value: This function returns a string-type value. Possible values for the returned string are: booleanintegerdouble (for historical reasons "double" is returned in case of float)stringarrayobjectresourceNULLunknown typeBelow programs illustrate the gettype() function in PHP: Example 1: In this example we demonstrates the gettype() function, which identifies and prints the data types of various variables, including boolean, integer, double, string, array, object, null, and resource types. php <?php // PHP program to illustrate gettype() function $var1 = true; // boolean value $var2 = 3; // integer value $var3 = 5.6; // double value $var4 = "Abc3462"; // string value $var5 = array(1, 2, 3); // array value $var6 = new stdClass; // object value $var7 = NULL; // null value $var8 = tmpfile(); // resource value echo gettype($var1)."\n"; echo gettype($var2)."\n"; echo gettype($var3)."\n"; echo gettype($var4)."\n"; echo gettype($var5)."\n"; echo gettype($var6)."\n"; echo gettype($var7)."\n"; echo gettype($var8)."\n"; ?> Outputboolean integer double string array object NULL resource Example 2: In this example we use the gettype() function to identify and print the data types of variables, including a string, integer (modulus operation), integer (power), double (square root), and double. php <?php // PHP program to illustrate gettype() function $var1 = "GfG"; $var2 = 10 % 7; $var3 = pow(10, 2); $var4 = pow(10, 0.5); $var5 = sqrt(9); echo gettype($var1)."\n"; echo gettype($var2)."\n"; echo gettype($var3)."\n"; echo gettype($var4)."\n"; echo gettype($var5); ?> Outputstring integer integer double double Comment More infoAdvertise with us Next Article PHP gettype() Function M Mithun Kumar Follow Improve Article Tags : Misc Web Technologies PHP PHP-function Practice Tags : Misc Similar Reads PHP | imagetypes() Function The imagetypes() function is an inbuilt function in PHP which is used to return the image types supported by the PHP inbuilt installed library. Syntax: int imagetypes( void ) Parameters: This function does not accept any parameter. Return Value: This function returns the bit-field corresponding to t 1 min read PHP | exif_imagetype() function The exif_imagetype() function is an inbuilt function in PHP which is used to determine the type of an image.Syntax:Â Â int exif_imagetype( string $filename ) Parameters:This function accepts a single parameter $filename which holds the name or URL of the image.Return Value: This function returns an i 1 min read PHP | gettimeofday() Function The gettimeofday() function is an inbuilt function in PHP which is used to return the current time. It is an interface to Unix system call gettimeofday(2). It returns an associative array containing the data returned from the system call. The float option is sent as a parameter to the gettimeofday() 2 min read PHP | getprotobynumber() Function The getprotobynumber() function is an inbuilt function in PHP which returns the protocol name for a specified protocol number. Syntax: string getprotobynumber( int $protocol_number ) Parameters: This function accepts single parameter $protocol_number which is required. It specifies the protocol numb 1 min read PHP | SplFileInfo getType() Function The SplFileInfo::getType() function is an inbuilt function of Standard PHP Library (SPL) in PHP which is used to get the file type. Syntax: string SplFileInfo::getType( void ) Parameters: This function does not accept any parameter. Return values: This function returns the type of file i.e. link, di 1 min read PHP | get_class() Function The get_class() function is an inbuilt function in PHP which is used to return the class name of an object. Syntax: string get_class( object $object ) Parameters: This function accepts single parameter $object which holds the object that need to be tested. The value of this parameter can be omitted 1 min read PHP | settype() Function The settype() function is a built-in function in PHP. The settype() function is used to the set the type of a variable. It is used to set type or modify type of an existing variable. Syntax: boolean settype($variable_name, $type) Parameters: The settype() function accepts two parameters as shown in 2 min read PHP | IntlCalendar getType() Function The IntlCalendar::getType() function is an inbuilt function in PHP which is used to get the calendar type in terms of string. The "calendar" is the valid value of keywords. Syntax: Object oriented stylestring IntlCalendar::getType( void )Procedural stylestring intlcal_get_type( IntlCalendar $cal ) P 1 min read PHP | Imagick getImageType() Function The Imagick::getImageType() function is an inbuilt function in PHP which is used to get the potential image type. Syntax: int Imagick::getImageType( void ) Parameters: This function doesnât accepts any parameter. Return Value: This function returns an integer value corresponding to one of IMGTYPE co 1 min read PHP | Gmagick getimagetype() Function The Gmagick::getimagetype() function is an inbuilt function in PHP which is used to get the image type. Syntax: int Gmagick::getimagetype( void ) Parameters: This function doesnât accept any parameters. Return Value: This function returns an integer value corresponding to one of the IMGTYPE constant 1 min read Like