• PHP Video Tutorials

PHP - gettype() Function


Advertisements

Definition and Usage

The function gettype() returns type of a variable.

Syntax

string gettype ( mixed $value )

Parameters

Sr.No Parameter & Description
1

value

The variable whose type will be checked.

*mixed: mixed indicates that a parameter may accept multiple (but not necessarily all) types

Return Values

This function returns a string. Possible values for the returned string are −

  • boolean

  • integer

  • double (for historical reasons double is returned in case of a float, and not simply float)

  • string

  • array

  • object

  • resource

  • resource (closed) (as of PHP 7.2.0)

  • NULL

  • unknown type

Dependencies

PHP 4.0 and above

Example

Following example demonstrates the use of gettype() for different types of variables −

<?php
   $data = array(2, 2.0, NULL, new stdClass, 'tutPoint', true, array(1, 2, 3), tmpfile());

   foreach ($data as $value) {
      echo gettype($value);
   }
?>

Output

This will produce following result −

integer
double
NULL
object
string
boolean
array
resource
php_variable_handling_functions.htm

Useful Video Courses


Video

PHP Online Training

45 Lectures 9 hours

Malhar Lathkar

Video

Become PHP Facebook Developer: Password-Less Authentication

34 Lectures 4 hours

Syed Raza

Video

Ultimate PHP & MySQL Web Development Course & OOP Coding

84 Lectures 5.5 hours

Frahaan Hussain

Video

Learn PHP from Scratch

17 Lectures 1 hours

Nivedita Jain

Video

E Commerce Website Development In PHP With PDO

100 Lectures 34 hours

Azaz Patel

Video

PHP in Telugu

43 Lectures 5.5 hours

Vijay Kumar Parvatha Reddy

Advertisements