PHP gettype() Function Tutorial

Notes:

gettype() function in PHP: Displaying type of variables in PHP

gettype function:
- is a variable handling function used to display the type of data.

Syntax:
gettype(data) : string;
where: data : can be a data value, variable name or constant name

Let’s prove:

$playerScore= 10; // playerScore variable is holding integer type of data
$playerSpeed=3.5;// playerSpeed variable is holding double type of data
$playerName=”Manjunath”; // playerName variable is holding string type of data
$isGameOver=true; // isGameOver variable is holding boolean type of data
$names = array("rama","ravi");// names variable is holding array type of data
$point1 = new Point(); // point1 variable is holding object type of data
$point1=null; // point1 variable is holding NULL type of data
$file = fopen("index.php","r"); // file variable is holding resource type of data

Example Code:

<?php

echo gettype("Hello World"),"<br/>"; // string

$playerScore=10;
echo gettype($playerScore),"<br/>"; // integer

$playerSpeed=3.5;
echo gettype($playerSpeed),"<br/>"; // double

$playerName1="Manjunath";
echo gettype($playerName1),"<br/>"; // string

$playerName2='Manjunath';
echo gettype($playerName2),"<br/>"; // string

$isGameOver=true;
echo gettype($isGameOver),"<br/>"; // boolean

$names = array("Ravi","Rama","Raju");
echo gettype($names),"<br/>"; // array

class Point
{
public $x;
public $y;
}

$point1 = new Point();
echo gettype($point1),"<br/>"; // object

$point1 = null;
echo gettype($point1),"<br/>"; // NULL

$file = fopen("index.php","r");
echo gettype($file),"<br/>"; // resource

const PI=3.142;
echo gettype(PI),"<br/>"; // double
?>

Interview Questions:

1. PHP stands for ______________
a. Hypertext Preprocessor
b. Preprocessor Hypertext
c. Personal Home Processor
d. Personal Hypertext processor
Ans: a