w3resource

php.js : gettype() function

gettype() function

The gettype() function returns the type of a variable.

Version:

1103.1210

Syntax

gettype(variable_name)

Parameters:

Name Description Required /
Optional
Type
variable_name The name of the variable. Required Mixed*

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

Example of php.js gettype() function:

In the following web document gettype() function returns the type of different variables.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>php.js : gettype() function example</title>
<script type="text/javascript" src="../../phpjs/variable/variable.min.js"> </script>
</head>
<body>
<h1 style="color: green">php.js : gettype() function example</h1>
<h3>Type of the various variable.</h3>
<hr />
<script type="text/javascript">
//This is done to make the following JavaScript code compatible to XHTML. <![CDATA[
x='abc';
y=new Array(12,13,14,15);
z=new Date();
document.write(gettype(x)+'<br />');
document.write(gettype(y)+'<br />');
document.write(gettype(z)+'<br />');
//]]>
</script>
</body>
</html>

Output of the function:

string
array
date

View example of php.js gettype() function in browser

Download phpjs.zip

Previous: php.js : get_resource_type() function
Next: php.js : intval() function



Share this Tutorial / Exercise on : Facebook and Twitter